KeydownAnimationGlitch?

Talk about making games.

KeydownAnimationGlitch?

Postby Kooldudese » Wed Aug 13, 2008 7:10 pm

Well, ill get straight to the point, i have a problem with keydown animation. In my case i have an actor with a left or right keydown animation ( walking ) and the problem is that if i put an "ChangeAnimation on keydown repeat enabled" then the actor contiuously reverts the animation ( so in result it only shows the first few frames of the animation, and then it automatically goes back to the begginning in a loop ) and if i was to put "ChangeAnimation on keydown repeat disabled" it would only do that animation once. the problem here is that i want the animation to be set while keydown.. not that it changes animation continuously while keydown. Well, ty for the help.. :D
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: KeydownAnimationGlitch?

Postby feral » Wed Aug 13, 2008 10:27 pm

I am sure there is an easier way,( haven't finish my first coffee yet :lol: )
but try

on key down

if (animindex!=1) //if not equal required animation index '1' or 2 or 3 or whatever
{
ChangeAnimation("Event Actor", "animationname", FORWARD); //change to required animation
}

you could also use getAnimName() if you wanted to check by it actual name instead of index number
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: KeydownAnimationGlitch?

Postby Kooldudese » Thu Aug 14, 2008 6:41 pm

This sounds like a nooby question but what does the animation index refer to?
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: KeydownAnimationGlitch?

Postby Kooldudese » Thu Aug 14, 2008 6:46 pm

Btw, it doesnt seem to work
post demo on what you mean? plz
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: KeydownAnimationGlitch?

Postby Thanx » Thu Aug 14, 2008 8:42 pm

k, here's what I think is apropriate:
Make variable: Canstartnewanimation or something that's like that, anyway, I'll refer to the variable with that long name.

In Keydown event, which is Repeat ENABLED:
if(Canstartnewanimation == 1)
{
ChangeAnimation(the apropriate animation);
Canstartnewanimation = 0;
}
//other code for moving goes here

Now there has to be an Animation Finish event. There do this line:
Canstartnewanimation = 1;
In the create action of the actor make the variable 0. That's it, I think the problem should be solved with that! :wink:
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: KeydownAnimationGlitch?

Postby feral » Thu Aug 14, 2008 10:47 pm

Kooldudese wrote:This sounds like a nooby question but what does the animation index refer to?


animindex refers to the index number of the selected animation.

in otherwords, if your actor has has four animations , left, right, up , down.. as you load the animations into the game by using the Add Animation button, each one receives an index number in the order they are loaded.

so if you were to load the animations "left, right, up , down" in that order, left would receive an index number of 0, then right would receive an index of 1, up receives 2.. etc..

note: the only problem with it is,.. if you delete an animation, and reload it , it can upset the index order, so you will need to check what the new index numbers are.. they will be the same as the order the animation names show in the popup box you see when you select animations using the dialogue box - so if you change the order just check the list of animations again

anyhow.. the code I posted before checks to see if the correct animation is loaded... by checking the index number.

if the correct one is already loaded it won't load it again.. this stops the animation from starting at the beginning frame, each time the key is pressed - (becuase each time an animation is loaded, it starts at the first ( or last frame)

so,.. if the correct animation is already loaded - don't reload it..

Code: Select all
if (animindex!=1)   //if not equal to the required animation  - index '1' (in this case -  1)
                                       //or 2 or 3 or whatever the correct index number is
{
ChangeAnimation("Event Actor", [i]'animationname"[/i], FORWARD); //then change to required animation -
                                                                                               //and now that the correct one is now loaded
                                                                                                //it won't get loaded again
}


if you cannot figure out what the correct animindex actually is.. create a text actor (usually called debug )and in the keydown event write

Code: Select all
ChangeAnimation("Event Actor", "animationname", FORWARD);
debug.textNumber=animindex;


this will tell you the animindex of the one you are trying to select - you can then replace it with the code above..

attached is a demo - left - right keys to change animations
ch_index.zip
ged/data
(20.19 KiB) Downloaded 113 times


note: the solution by thanx should also work.. but... I believe it is definitely worth getting used to the animindex variable as it can be very useful... for example you can use this to tell what animation other actors are using,.. from any actor.

eg: in the firing keydown of the player actor you could do something like
Code: Select all
int whatanim;
whatanim=enemy.animindex;
if (whatanim==1)  //animindex of the animation of the enemy with shield up..
{
//then enemy has shield  -
//code here
}
else
{
canshoot=1;
}



from the GE script reference
animindex: Use animindex(count from 0) to find the actual animation of your actor. Each animation that an actor has has a unique index assigned to it. ( This way you can tell which animation is currently running. )
If your actor has 3 animations, then:
The first animation has animindex = 0
The second animation has animindex = 1
The third animation has animindex = 2
This variable is read only.



oops ..long post..sorry :?
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: KeydownAnimationGlitch?

Postby Kooldudese » Fri Aug 15, 2008 12:17 am

Thx for the help :D
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: KeydownAnimationGlitch?

Postby Bee-Ant » Tue Aug 19, 2008 1:22 pm

Here's the short version.
1. Make an actor variable called "anim"
2. Put this code on Keydown>Left
Code: Select all
x-=3;
if(anim==0)
{
    ChangeAnimation("Event Actor","WalkLeft",FORWARD);
    anim=1;
}

Keydown>Right
Code: Select all
x+=3;
if(anim==0)
{
    ChangeAnimation("Event Actor","WalkRight",FORWARD);
    anim=1;
}

3. Put this code on AnimationFinish>Any Animation
Code: Select all
anim=0;
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron