one key at a time!

Non-platform specific questions.

one key at a time!

Postby Toasterman » Sun Jul 25, 2010 6:03 pm

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?)
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: one key at a time!

Postby MrJolteon » Sun Jul 25, 2010 6:13 pm

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 :)
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: one key at a time!

Postby Toasterman » Sun Jul 25, 2010 6:49 pm

Thanks Alot! :lol:
Fixed that stupid moonwalk problem that I figured I would always be stuck with!
A point for you! :D
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: one key at a time!

Postby Toasterman » Sun Jul 25, 2010 7:23 pm

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:
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest