Need help with Keyboard Imput
by Reitter Philipp · in Technical Issues · 07/21/2008 (5:57 pm) · 9 replies
Hi...
currently i am using:
moveMap.bindCmd(keyboard, "right", "mRight();", "");
this function to set the angle of my airplane 10 degrees up...
but the function is only called onKeyDown and this is not good...
can any 1 help me plz?
i thought of on down: Left = true on up Left = false
but where to set the angle then... ther is nothing like a main loop...
thanks
Flario
currently i am using:
moveMap.bindCmd(keyboard, "right", "mRight();", "");
this function to set the angle of my airplane 10 degrees up...
but the function is only called onKeyDown and this is not good...
can any 1 help me plz?
i thought of on down: Left = true on up Left = false
but where to set the angle then... ther is nothing like a main loop...
thanks
Flario
#2
but i want a function to be called again and again while the key is down...
or is there any other way to make my airplane flying smooth curves like in any other game
because its really uncool only set the angle +10 on key down....
i hope you understand what i mean...
sorry for my bad english
Mfg
Flario
07/21/2008 (7:30 pm)
Yea but this code is only called onPress or onReleasebut i want a function to be called again and again while the key is down...
or is there any other way to make my airplane flying smooth curves like in any other game
because its really uncool only set the angle +10 on key down....
i hope you understand what i mean...
sorry for my bad english
Mfg
Flario
#3
07/21/2008 (7:31 pm)
Look at some of the input behaviors on the TDN
#4
[Sidenote: Yes it is basically ripped from the TGB platformer tutorial so if you have access to TGB go read that. If not you should still get the gist of it]
07/21/2008 (7:38 pm)
Excuse the pseudo-code that may not work exactly as shown but it should give you the basic idea.[Sidenote: Yes it is basically ripped from the TGB platformer tutorial so if you have access to TGB go read that. If not you should still get the gist of it]
moveMap.bindCmd(keyboard, "right", "startTurn()", "stopTurn()");
function startTurn()
{
$player.turning = true;
}
function stopTurn()
{
$player.turning = false;
}
function player::onUpdate(%this)
{
if($player.turning)
{
// Update angle junk
}
}
#5
or gets onUpdate called by the class itself?
07/21/2008 (7:40 pm)
Yea i had this idea but the onUpdate function has to be called?or gets onUpdate called by the class itself?
#6
%this.enableUpdateCallback();
thanks!
but only one question:
if somone has a faster CPU and GPU will the function then be called more often
because then some players will be able to move faster...
or is ther anywhere the variable for the time dif between 2 frames?
thanks
Flario
07/21/2008 (7:44 pm)
Ah just found this line:%this.enableUpdateCallback();
thanks!
but only one question:
if somone has a faster CPU and GPU will the function then be called more often
because then some players will be able to move faster...
or is ther anywhere the variable for the time dif between 2 frames?
thanks
Flario
#7
Next - go search through TDN its educational.
Lastly, in TGB at least I'm certain (and I'm sure the other engines would be coded similarly) the update is called at a constant rate. From TDN:
Edit: Also if you are using TGB I highly recommend reading the platformer tutorial I linked above as it would have answered all of these questions (except the CPU / GPU one - I actually had to go look that one up).
07/21/2008 (7:50 pm)
First off are you use using TGB, TGE, TGEA, etc?Next - go search through TDN its educational.
Lastly, in TGB at least I'm certain (and I'm sure the other engines would be coded similarly) the update is called at a constant rate. From TDN:
Quote:
OnUpdate
This is called every tick (32 milliseconds). It should be used only when necessary as it can have pretty serious performance implications. Because of this, it must be enabled with a call to enableUpdateCallback. It can be disabled by calling disableUpdateCallback.
Edit: Also if you are using TGB I highly recommend reading the platformer tutorial I linked above as it would have answered all of these questions (except the CPU / GPU one - I actually had to go look that one up).
#8
07/21/2008 (8:32 pm)
Ok thanks!
#9
moveMap.bind() does precisely what you want it to do already with the example James posted, with one adjustment however.
The important bit of code here is the if(%val) check inside the turnRight function. In the above example, turnRight will continually be called for as long as I hold down the D key. Once the key is let up, the function will cease being called and the last call made to it will not update the turn as the it will not get past the if check. To further expand on this, you can add an else statement to that if check. The code in that else statement would only be called upon release of the key.
07/22/2008 (6:05 am)
@ ReittermoveMap.bind() does precisely what you want it to do already with the example James posted, with one adjustment however.
moveMap.bind(keyboard, "D", "turnRight")
function turnRight(%val)
{
if(%val)
{
//turning code goes here
}
}The important bit of code here is the if(%val) check inside the turnRight function. In the above example, turnRight will continually be called for as long as I hold down the D key. Once the key is let up, the function will cease being called and the last call made to it will not update the turn as the it will not get past the if check. To further expand on this, you can add an else statement to that if check. The code in that else statement would only be called upon release of the key.
Associate James Ford
Sickhead Games
You should use moveMap.bind instead of moveMap.bindCmd
moveMap.bind(keyboard, "right", "mRight");
function mRight( %val )
{
// %val == 1 onKeyPress
// %val == 0 onKeyRelease
}