EventReceiver and animation problem

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
ucoskun
Posts: 8
Joined: Thu May 17, 2007 4:26 pm
Location: Turkey
Contact:

EventReceiver and animation problem

Post 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?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vi-wer
Posts: 93
Joined: Sun May 20, 2007 7:15 pm
Location: Germany
Contact:

Post 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;
Post Reply