Changing animation

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
Watcher
Posts: 40
Joined: Sat Jul 01, 2006 9:44 am
Location: Czech republic

Changing animation

Post by Watcher »

Hi I´ve got one problem. How can i change animation of the node? The animation which I set when I create the node works well

Code: Select all

scene::IAnimatedMeshSceneNode* soldier = smgr->addAnimatedMeshSceneNode(
		smgr->getMesh("soldier.x"), camEnemy);
		
		soldier->setFrameLoop(124, 202);
		soldier->setAnimationSpeed(50);
but when I tried to change it - it doesn´t work. This code is refreshing.

Code: Select all

if (shoot == 1)
		{
                   
                   soldier->setFrameLoop(1, 29);
		           soldier->setAnimationSpeed(20);
		           shoot = 0;
        } 
that variable shoot is handled by event receiver.
cadue
Posts: 72
Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano

Post by cadue »

I had the same problem...but I don't remember how I fixed it :?
Try to change the frame loop and check if you set continually the frame loop...
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
Vuen
Posts: 25
Joined: Tue Jul 11, 2006 8:03 am

Post by Vuen »

Every time you call setAnimationSpeed, it resets the animation. So if your variable shoot is staying true for an extended period of time, then that chunk of code will just jam the animation.

You'll need to hold a variable that says what animation the node is currently playing, and if it's not already shooting, then set the frame loop and animation speed.
Watcher
Posts: 40
Joined: Sat Jul 01, 2006 9:44 am
Location: Czech republic

Post by Watcher »

That should be it, but I have no idea how to handle it. Please look at my code where should be the mistake.

Code: Select all

bool shoot = 0;
bool mousealreadypreesed = 0;
//scene::IAnimatedMeshSceneNode* anms = 0;
IrrlichtDevice* device = 0; 

        ///////////////////////////////event reciever/////////////////
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{ 
 if(event.EventType == EET_MOUSE_INPUT_EVENT) 
{ 
switch(event.MouseInput.Event) 
{ 
case EMIE_LMOUSE_PRESSED_DOWN:
{
if (mysuzstisknuta == 0)
   {
                   shoot = 1;
                   mousealreadypreesed = 1;
   }                 
} 
case EMIE_RMOUSE_PRESSED_DOWN:
{ 
}
return true; 
} 
} 
return false; 
} 
};

Code: Select all

scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(
		smgr->getMesh("player_gun.x"));
		
		anms->setFrameLoop(1, 29);
		anms->setAnimationSpeed(20);
		anms->setLoopMode(false);
		 anms->setParent(camera);
   anms->setRotation(core::vector3df(0,90,0));
   anms->setPosition(core::vector3df(-1,2,-5));

That was the node creation code which works well.

Code: Select all

if (shoot == 1)
		{
                   
                   anms->setLoopMode(false);
                   anms->setAnimationSpeed(20);
                   
                    
		           
		           shoot = 0;
        }                      
And finally the loap code. If I let the animation loap it works but it seems to me tah it doesn´t start from first frame. And if I set the animation loap to false, animation doesn´t start.
Post Reply