Page 1 of 1

EventReceiver and animation problem

Posted: Fri Jul 27, 2007 10:19 pm
by ucoskun
My codes are

Code: Select all

bool wpressed;
bool spressed;
bool walk;

class CEventReceiver_eg3 : public IEventReceiver
{
public:
	CEventReceiver_eg3()
	{
	}
	~CEventReceiver_eg3()
	{
	}
	bool OnEvent(SEvent event)
	{
		if(event.EventType == EET_KEY_INPUT_EVENT&&event.KeyInput.PressedDown == true)
		{

			if(event.KeyInput.Key == KEY_KEY_W)
			{
					wpressed=true;
					walk=true;
				    }
			
			if(event.KeyInput.Key == KEY_KEY_S)
			{
                    spressed=true;
                    walk=true;
	                }

		
		}
				else if(event.KeyInput.PressedDown == false)
				{
				wpressed=false;
				spressed=false;
				walk=false;
				}
		return false;
	}
};

Code: Select all

while (device->run())
{
		
if (wpressed==true)
{
plnode->setPosition(vector3df(plnode->getPosition().X + 2 , plnode->getPosition().Y,plnode->getPosition().Z));
}
else if (spressed==true)
{
plnode->setPosition(vector3df(plnode->getPosition().X -2 , plnode->getPosition().Y,plnode->getPosition().Z));
}
if(walk=true)
{
               plnode->setFrameLoop(250,800);
               plnode->setAnimationSpeed(40);
}
}
When I press W or S , my model doesn't animate. What's my problem?

Posted: Fri Jul 27, 2007 10:31 pm
by Acki

Code: Select all

if(walk=true) 
must be

Code: Select all

if(walk==true) 
or simply

Code: Select all

if(walk) 
but your code should cause the node always to animate, so are you sure the animations of the node are correct ???
also look in your previous thread...

Posted: Sat Jul 28, 2007 10:02 am
by vi-wer
Your animation will start from the beginning everytime
if(walk==true)
is checked.
You need another variable that tells you if the animation is already running or not. Like this:

Code: Select all

if( walk )
{
  if( !animation_on )
  {
     animation_on = true;
     plnode->setFrameLoop(250,800);
     plnode->setAnimationSpeed(40); 
  }  
}
else
   animation_on = false;