Page 1 of 1

Actor moving problem

PostPosted: Sat Nov 20, 2010 7:55 pm
by schnellboot
Hey,
I already coded the part with
a -> actor.x -= 5;
d -> actor.x += 5;
w -> actor.y -= 5;
s -> actor.y += 5;

know if I press d and then w my actor moves x + 5 and y - 5, but I want my actor only move in one direction.
example:
d and then w : x + 5
s and then d : y + 5

how can I do that?

Re: Actor moving problem

PostPosted: Sat Nov 20, 2010 11:23 pm
by skydereign
Quickest way is to set a lock variable. So create a variable, in my case moving. There are 5 possible values for moving. 0 is no key pressed, 1 is right, 2 is up, 3 is left, 4 is down. On your keydown events, it should look like this.
actor -> Keydown (right) -> Script Editor
Code: Select all
if(moving==0) // no key pressed
{
    x+=5; // switch these to the appropriate x or y
    moving=1; // set this to the appropriate value
}

actor -> Keyup (right) -> Script Editor
Code: Select all
if(moving==1)
{
    moving=0;
}


If you want you can #define or enum the values for left, up, right, and down, so that typing the word left, will be the same as typing 3.

Re: Actor moving problem

PostPosted: Sun Nov 21, 2010 7:21 am
by schnellboot
please check this out
[urlhttp://www.multiupload.com/BYG7DONQ3D][/url]

click game game mode and move with w, a, s ,d

coded everything as you told me

Re: Actor moving problem

PostPosted: Sun Nov 21, 2010 8:19 am
by skydereign
Sorry, forgot the || case. As you noted, it only operates once, and it is because the keydown sets move not to equal zero. With xvelocity and yvelocity you don't need to do that, and originally I was going to suggest using xvelocity and yvelocity (no need for repeat events).
Code: Select all
if(moving==0 || moving==1)
{
    x+=5;
    moving=1;
}

Re: Actor moving problem

PostPosted: Sun Nov 21, 2010 5:27 pm
by schnellboot
thanks, but I tried it out and now I want it like that
if you press d and then w actor should move y-5 how can I do that?