Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: IsKeyDown freezes animation  (Read 3449 times)

0 Members and 1 Guest are viewing this topic.

Deydren

  • never sleeping
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 7
  • NomNomNom
    • View Profile
IsKeyDown freezes animation
« on: June 27, 2011, 06:38:11 AM »

Hello all!

I'm trying to do some pretty unusual stuff with this really awesome engine, and till now I found a way to solve all every problem with a small amount of creativity or a large amount of forum-search ;D But now I'm stuck... It's 7am here in Germany and I've been trying to find a work-around for about 6 hours by now. So excuse my inevitable spelling and grammar fails  ::slug

Well, the problem is, that I want a 2D actor to play a specific animation, while a key is pressed. So I thought, code should look like this (inside a "while"-loop):

Code: [Select]
if(Keyboard.IsKeyDown(VK_RIGHT))
{
actor.PlayAnimAsync("walk");
}

But nope. It doesn't work  :-[ I've varied the code a thousand times by now, but the "IsKeyDown" seems to make the animation freeze on the first frame, 'cause it is called again and again as long as I keep my finger on the key...
With a 3D actor, I would solve the Problem with a "actor.IsAnimPlaying" but this doesn't work for 2D actors :(

Please help me, or I will never get to sleep.......  :'(
Logged

Mihulik

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 71
    • View Profile
Re: IsKeyDown freezes animation
« Reply #1 on: June 27, 2011, 06:51:52 AM »

Declare a global variable that indicates that the animation has started playing. ;)
Logged

Deydren

  • never sleeping
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 7
  • NomNomNom
    • View Profile
Re: IsKeyDown freezes animation
« Reply #2 on: June 27, 2011, 01:53:00 PM »

Thx. I had the same thought, but if I do that, the animation only plays the first frame and then instantaniously jumps back to the idle animation... So, still irritated over here...
Logged

Deydren

  • never sleeping
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 7
  • NomNomNom
    • View Profile
Re: IsKeyDown freezes animation
« Reply #3 on: June 27, 2011, 02:13:18 PM »

Defined a global variable called "walkplaying" and changed code to:

Code: [Select]
while(true)
{

[...]

if(Keyboard.IsKeyDown(VK_RIGHT) )
{
                 if(!walkplaying) actor.PlayAnimAsync("walk");
                 walkplaying=true;
                }

[...]

if(!Keyboard.IsKeyDown(VK_RIGHT)) walkplaying=false;

}

Still not working. Can't find my error :(

Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: IsKeyDown freezes animation
« Reply #4 on: June 27, 2011, 07:31:54 PM »

Could perhaps a sleep() command provide a solution to the problem?
Logged
 

Page created in 0.041 seconds with 24 queries.