[SOLVED] Animation help...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ReturnZero
Posts: 4
Joined: Fri Jul 03, 2009 7:05 pm

[SOLVED] Animation help...

Post by ReturnZero »

Well, my problem is, is that only one frame of my animation frame is rendered.

My code looks like this

Code: Select all


main loop()
{
    if (receiver.IsKeyDown(irr::KEY_KEY_W) || receiver.IsKeyDown(irr::KEY_KEY_A) ||  receiver.IsKeyDown(irr::KEY_KEY_S) || receiver.IsKeyDown(irr::KEY_KEY_D))
	{
		 visualNode->setAnimationSpeed(40);
		 visualNode->setFrameLoop(2,14);
	}
	else //idle animation.
	{
		visualNode->setAnimationSpeed(40);
		 visualNode->setFrameLoop(292,360);
	}
}
If this helps... my event receiver looks like this:

Code: Select all

class MyEventReceiver: public IEventReceiver
{
public:

    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == EET_MOUSE_INPUT_EVENT)
        {
            cursor.X = event.MouseInput.X;
            cursor.Y = event.MouseInput.Y;
        }
		 

        if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
        {
            cameraDistance += -event.MouseInput.Wheel* (cameraDistance / 20) * 3;
            if(cameraDistance < 10) cameraDistance = 10;
        }

        if(event.EventType == EET_KEY_INPUT_EVENT)
        {
             KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
        }
 
        return false;
    }

			virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                 return KeyIsDown[keyCode];

        }

		MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }



			

			private:
				 bool KeyIsDown[KEY_KEY_CODES_COUNT];

 
};
As I said before, Only one frame of my animation is played, instead of the ones I wanted to play ,, (2,14) ..etc

Hope you can help :)
Last edited by ReturnZero on Fri Jul 03, 2009 10:37 pm, edited 1 time in total.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

You need to call it only once, because this way the animation starts every frame and only the first frame is shown. You should check if a key has been pressed the last step or sth similar. Use some variables like "currentAnimation" and "willingAnimation" and if( currentAnimation!=willingAnimation ) then set your loop etc. :wink:

You can use sth like (this is very lame way doing this):

Code: Select all

// before the main loop
int willingAnim = 0;
int currentAnim = 0;

// inside your main loop

if (receiver.IsKeyDown(irr::KEY_KEY_W) || receiver.IsKeyDown(irr::KEY_KEY_A) ||  receiver.IsKeyDown(irr::KEY_KEY_S) || receiver.IsKeyDown(irr::KEY_KEY_D))
   {
        willingAnim = 2;
   }
   else 
   {
        willingAnim = 1;
   } 



if(willingAnim!=currentAnim)
{ 
currentAnim = willingAnim;
 if(currentAnim == 1)
    {  
       visualNode->setAnimationSpeed(40);
       visualNode->setFrameLoop(292,360);
    }
 if(currentAnim == 2)
    {
       visualNode->setAnimationSpeed(40);
       visualNode->setFrameLoop(2,14);
    }
}
Didn`t tried it, but it should be working.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
ReturnZero
Posts: 4
Joined: Fri Jul 03, 2009 7:05 pm

Post by ReturnZero »

Thank you, It works!
.....
.....
Thanks again :)
Post Reply