Walk 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
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Walk animation

Post by 3DModelerMan »

Hey, I'm trying to make a system for animation, it only needs to change the animation if the animation is different than the last one. For some reason this isn't working

Code: Select all

void CAnimatedHuman::setWalkTrack(SAnimation* anim)
{
 //Null animation means to just turn it off
 if ( anim == 0 )
 { 
  m_walkTrack->setFrameLoop(0,0);
  m_currentWalkTrack = 0;
  return;
 }
 //Only update if the animation is different
 if ( anim != m_currentWalkTrack )
 {
  m_walkTrack->setFrameLoop(anim->m_startFrame, anim->m_endFrame);
  m_walkTrack->setLoopMode(anim->m_loop);
 }

 m_currentWalkTrack = anim;
}
SAnimation just stores whether to loop or not, and the frame numbers.
Where did I go wrong?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

does anyone have any ideas?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Walk animation

Post by greenya »

3DModelerMan wrote:For some reason this isn't working
What particular doesn't work: it updates every time or never updates or what?

Looking into your code:

Code: Select all

if ( anim != m_currentWalkTrack ) 
Here you compare pointers, which is might be not what you need. Pointers is OK to compare, if you have manager that stores all the pointers and you know that if any 2+ pointers in your application points to the same thing, they also contains the same address of the pointer of the item in manager.

I do not see all the code, so i only suppose. If you calling your CAnimatedHuman::setWalkTrack in the next way:

Code: Select all

SAnimation* a = new SAnimation(1,2,3...);
animatedHumanInstance->setWalkTrack(a);
delete a;
then "m_currentWalkTrack" and "anim" will always differ.
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

i've done this thousands of times. theres no need to have a function specific to each animation just do something like:

Code: Select all

void setAnimation(int start, int end){
    if(node->getFrameNr()<start || node->getFrameNr()>end){
        node->setFrameLoop(start,end);
    }
}
with this end must be greater than start, and animations cant share frames
Image
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

Okay, thanks. :D
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Post Reply