HELP! Key up affecting key down event!

You must understand the Game Editor concepts, before post here.

HELP! Key up affecting key down event!

Postby an0nyme » Sun Nov 15, 2009 1:46 am

I have animated actors for when I press left or right key, and I have another animation for both directions for key up, when the character isn't walking. The problem is that when i change direction, the character animation doesn't change to the one I set for key down, it uses the one I set for key up for the other direction, since I have released the other key. So it means that if my character was walking towards the right and I press the left arrow to change direction, my character just slides to the left while still facing right and not making the walking movement.

Is there a way to fix this? It doesn't happen all the time but very often, sometime the animations are normal depending on if I press the key of the direction I want my character to move twice in a row but it's kinda annoying...

Please help me! :(
an0nyme
 
Posts: 7
Joined: Sun Nov 15, 2009 1:21 am
Score: 0 Give a positive score

Re: HELP! Key up affecting key down event!

Postby krenisis » Sun Nov 15, 2009 7:12 am

hey how u doing? ok if i understand u correctly this be a simple fix
ok lets say u have a actor.he has two animations actor left and actor right for example.This is how i would code him to change directions.
0) key down press right key ,,then script editor,,put
1st ) x=x+5;
2nd) now i go down to variable on botton of screen click it...then i go to change animation ....click on that....now a small screen pops up...i select ,actor right animation,forword then click ok

now we going to key down,, click left,,then script editor,,put
!st) x=x-5;
2) now i go down to variable on bottom of screen click it...then i go to change animation..click on that...now a small screen pops up..i select
actor left animation,forword then click ok

now when u press right arrow actor moves right with the animation u selected
and when u press left arrow actor move with the animation u selected
if you dont understand just tell me and i will explain simpler to you.Hope ur game turns out great and have fun
krenisis
 
Posts: 607
Joined: Sat Jul 25, 2009 3:27 pm
Score: 51 Give a positive score

Re: HELP! Key up affecting key down event!

Postby MrJolteon » Sun Nov 15, 2009 7:17 am

Do this:
In keydown right\script editor
Code: Select all
direct = 1;

and in keydown left\script editor
Code: Select all
direct = 2;

and in draw actor\script editor(add new)
Code: Select all
if (direct == 1)
{
ChangeAnimation("Event Actor", "right", NO_CHANGE);
actor.x=actor.x + 5;
}

if (direct == 2)
{
ChangeAnimation("Event Actor", "left", NO_CHANGE);

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

and in key up all keys(right click)\script editor add this:
Code: Select all
direct = 0;

You need to add the
Code: Select all
direct
variable first. to do this, goto any script\variables\add\name: direct\ok
Owner of the #GameEditor IRC channel at esper.net
User avatar
MrJolteon
 
Posts: 1940
Joined: Sat Aug 09, 2008 3:25 pm
Location: Fifth Layer
Score: 76 Give a positive score

Re: HELP! Key up affecting key down event!

Postby MrJolteon » Sun Nov 15, 2009 7:21 am

you caught me there, krenisis, but my method is with anti-moonwalk as well.
Owner of the #GameEditor IRC channel at esper.net
User avatar
MrJolteon
 
Posts: 1940
Joined: Sat Aug 09, 2008 3:25 pm
Location: Fifth Layer
Score: 76 Give a positive score

Re: HELP! Key up affecting key down event!

Postby an0nyme » Sun Nov 15, 2009 4:22 pm

Thank you for helping! But I forgot to precise one thing, my bad...

I have animation for the character when he's not walking too, and I have it facing both sides... I was wondering if there's a way to display that animation when I stop pressing the left or right keys too, and there's the problem: when I release the direction key and immediately press the other direction key, my character takes on the animation when he's not walking and just slides towards the new direction while facing the bad direction... I think it's because in key up event I made him change animation, and since when I press the other direction key I release the old one, the character moves in the new direction but uses the bad animation... I also put change animation in key down but it's not working.
an0nyme
 
Posts: 7
Joined: Sun Nov 15, 2009 1:21 am
Score: 0 Give a positive score

Re: HELP! Key up affecting key down event!

Postby MrJolteon » Mon Nov 16, 2009 4:12 pm

Use that code I gave you. It also stops your animation on key up.
Owner of the #GameEditor IRC channel at esper.net
User avatar
MrJolteon
 
Posts: 1940
Joined: Sat Aug 09, 2008 3:25 pm
Location: Fifth Layer
Score: 76 Give a positive score

Re: HELP! Key up affecting key down event!

Postby an0nyme » Tue Nov 17, 2009 12:22 am

It works perfectly now! I've modified a few little things in the code you gave me and problem fixed!
:D
an0nyme
 
Posts: 7
Joined: Sun Nov 15, 2009 1:21 am
Score: 0 Give a positive score

Re: HELP! Key up affecting key down event!

Postby an0nyme » Tue Nov 17, 2009 12:33 am

Thank you so much!
an0nyme
 
Posts: 7
Joined: Sun Nov 15, 2009 1:21 am
Score: 0 Give a positive score

Re: HELP! Key up affecting key down event!

Postby MrJolteon » Tue Nov 17, 2009 11:52 am

you're welcome
Owner of the #GameEditor IRC channel at esper.net
User avatar
MrJolteon
 
Posts: 1940
Joined: Sat Aug 09, 2008 3:25 pm
Location: Fifth Layer
Score: 76 Give a positive score

Re: HELP! Key up affecting key down event!

Postby Hblade » Sat Dec 12, 2009 9:12 pm

Why cant you just use "animindex" instead of change animation O.o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4381
Joined: Fri Dec 08, 2006 11:14 pm
Score: 170 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 0 guests