Page 1 of 1

one key at a time!

PostPosted: Sun Jul 25, 2010 6:03 pm
by Toasterman
I'm making a game in which the charactor is seen throught a top-down perspective.
I want him to move up, down, right, and left, but only move one direction at a time - not diagonaly.
How can I prevent other keys being pushed down while one of the other three is pressed?

Also, when I hold a button (up, for instance) then press another button, right, then let go of the up button, my charactor moves right as it should, but the animation still shows him walking up. I think this is because, for the change animation effect, it only detects the keydown initially (repeat is disabled) while the x and y movment itself is constantly updating. The animation is several frames long, so I can't make it update constantly. Or could I- is there a way to detect whether or not the actor is already playing an animation so it would not re-change animation every frame?

It is more of a trivial asthetics problem, not vital to the gameplay, but I would appreciate any responces!

(by the way, should this be posted under general or support?)

Re: one key at a time!

PostPosted: Sun Jul 25, 2010 6:13 pm
by MrJolteon
put these in the keydowns for the actor you dont want to moon walk

Code: Select all
Keydown up
direct = 1;

Code: Select all
keydown right
direct = 2;

Code: Select all
keydown down
direct = 3;

Code: Select all
keydown left
direct = 4;


and now in the draw actor of the same actor

Code: Select all
{
ChangeAnimation("Event Actor", "ups", NO_CHANGE);
actor.y = actort.y - 5;
}
if (direct == 2)
{
ChangeAnimation("Event Actor", "right", NO_CHANGE);
actor.x=actor.x + 5;
}
if (direct == 3)
{
ChangeAnimation("Event Actor", "downs", NO_CHANGE);
actor.y = actor.y + 5;
}
if (direct == 4)
{
ChangeAnimation("Event Actor", "left", NO_CHANGE);

actor.x = actor.x - 5;
}
if (direct == 0)
{
    ChangeAnimationDirection("Event Actor", STOPPED);
    animpos = 0;
}


Now you change actor to the name of your actor.

now that this does is the movement and the changing of the animation are set to a variable not a keydown. and they are both set to the same variable.

so looking right and going right can not be apart. if one is on the other one has to be. this way if you press both up and right. the actory will look and go either up or right. depending on what was pressed first.

a non flawable anty moon walk code using only if :)

Re: one key at a time!

PostPosted: Sun Jul 25, 2010 6:49 pm
by Toasterman
Thanks Alot! :lol:
Fixed that stupid moonwalk problem that I figured I would always be stuck with!
A point for you! :D

Re: one key at a time!

PostPosted: Sun Jul 25, 2010 7:23 pm
by Toasterman
crud- another problem:
when I implimented the code, my guy is stuck on the first frame of the walking animation- did I do something wrong?

EDIT: nevermind, I got it working after a little coding :mrgreen: