View Full Version : 2 button gameplay????
vin23
11-20-2007, 07:52 AM
hey guys, i need some help, im making a running based game, i need to control the characters movement, by pressing left, right, left right to run, the faster you push them in the order the faster you run, any ideas
if (Key.isDown(Key.RIGHT)) {
movement += 10;
}
cheers
alejandroquarto
11-22-2007, 09:04 PM
I think you can use some acceleration...something like:
accX=0
function renderCharacter(){
if (Key.isDown(Key.RIGHT)) {
accX+=0.1
}
if (Key.isDown(Key.LEFT)) {
accX-=0.1
}
_x+=accX
accX*=0.97 //If no key is pressed, then it will stop smothly
}
Quarto may have misunderstood you. That's a different control scheme, I think.
You want something where you are running just straight forward, and the alternating keys are for the left and right foot, right?
What you would want is keep track of the most recently pressed key, and every time it changes, move. That's more like:
accX=0;
prevKey="";
function renderCharacter(){
if ((Key.isDown(Key.RIGHT))&&(prevKey!="right")) {
prevKey="right";
accX+=0.1;
}
if ((Key.isDown(Key.LEFT))&&(prevKey!="right"))) {
prevKey="left";
accX+=0.1
}
_x+=accX
accX*=0.97 //If no key is pressed, then it will stop smothly
}
or if you don't want the acceleration, just:
accX=0;
prevKey="";
function renderCharacter(){
if ((Key.isDown(Key.RIGHT))&&(prevKey!="right")) {
prevKey="right";
_x+=1;
}
if ((Key.isDown(Key.LEFT))&&(prevKey!="right"))) {
prevKey="left";
_x+=1
}
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.