model 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
GundamO
Posts: 9
Joined: Thu Nov 11, 2010 11:34 am

model animation

Post by GundamO »

hey guys,

i have a model that has animation on it, i know how to loop the animation using the setFrameLoop function, but i was wondering how you get those frames to only play through once instead of looping?

thanks for any help
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

Code: Select all

		//! Sets looping mode which is on by default.
		/** If set to false, animations will not be played looped. */
		virtual void setLoopMode(bool playAnimationLooped) = 0;
GundamO
Posts: 9
Joined: Thu Nov 11, 2010 11:34 am

Post by GundamO »

For some reason the setLoopMode function isnt working for me.

Code: Select all

void Enemy::Update(float frameDeltaTime)
{
	core::vector3df pos = node->getPosition();
	core::vector3df player = turtle->node->getPosition();

	float DistancefromPlayer = pos.getDistanceFrom(player);

	if(pos.getDistanceFrom(player) > 110){//guard
		if(node->getFrameNr()> 10)
			node->setFrameLoop(1,11);

		enemyPosition.X += 30.0f * frameDeltaTime * cos((3.14 *(Eangle-90))/180);
		enemyPosition.Z -= 30.0f * frameDeltaTime * sin((3.14 *(Eangle-90))/180);
		Eangle += 0.2;
	}
	if(pos.getDistanceFrom(player) < 100 && pos.getDistanceFrom(player) > 51){//hide
		if(node->getFrameNr()> 76||node->getFrameNr() <65){
			node->setFrameLoop(66,77);
			node->setLoopMode(false);
		}
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	if(pos.getDistanceFrom(player) < 50){//die
		if(node->getFrameNr()> 64||node->getFrameNr() <50)
			node->setFrameLoop(51,65);
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	cout<<pos.getDistanceFrom(player)<<endl;
	enemyPosition.Y = land->terrain->getHeight(enemyPosition.X,enemyPosition.Z);
	node->setPosition(enemyPosition);
	node->setRotation(core::vector3df(0,Eangle,0));

}
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

GundamO wrote:For some reason the setLoopMode function isnt working for me.

Code: Select all

void Enemy::Update(float frameDeltaTime)
{
	core::vector3df pos = node->getPosition();
	core::vector3df player = turtle->node->getPosition();

	float DistancefromPlayer = pos.getDistanceFrom(player);

	if(pos.getDistanceFrom(player) > 110){//guard
		if(node->getFrameNr()> 10)
			node->setFrameLoop(1,11);

		enemyPosition.X += 30.0f * frameDeltaTime * cos((3.14 *(Eangle-90))/180);
		enemyPosition.Z -= 30.0f * frameDeltaTime * sin((3.14 *(Eangle-90))/180);
		Eangle += 0.2;
	}
	if(pos.getDistanceFrom(player) < 100 && pos.getDistanceFrom(player) > 51){//hide
		if(node->getFrameNr()> 76||node->getFrameNr() <65){
			node->setFrameLoop(66,77);
			node->setLoopMode(false);
		}
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	if(pos.getDistanceFrom(player) < 50){//die
		if(node->getFrameNr()> 64||node->getFrameNr() <50)
			node->setFrameLoop(51,65);
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	cout<<pos.getDistanceFrom(player)<<endl;
	enemyPosition.Y = land->terrain->getHeight(enemyPosition.X,enemyPosition.Z);
	node->setPosition(enemyPosition);
	node->setRotation(core::vector3df(0,Eangle,0));

}
maybe try calling

Code: Select all

setLoopMode();
OUTSIDE that function?

how often do you call

Code: Select all

 Enemy::update() 

EDIT: try this code....

Code: Select all

void Enemy::Update(float frameDeltaTime)
{
	core::vector3df pos = node->getPosition();
	core::vector3df player = turtle->node->getPosition();

	float DistancefromPlayer = pos.getDistanceFrom(player);

	if(pos.getDistanceFrom(player) > 110){//guard
		if(node->getFrameNr()> 10)
			node->setFrameLoop(1,11);

		enemyPosition.X += 30.0f * frameDeltaTime * cos((3.14 *(Eangle-90))/180);
		enemyPosition.Z -= 30.0f * frameDeltaTime * sin((3.14 *(Eangle-90))/180);
		Eangle += 0.2;
	}
	if(pos.getDistanceFrom(player) < 100 && pos.getDistanceFrom(player) > 51){//hide
		if(node->getFrameNr()> 76||node->getFrameNr() <65){
			node->setLoopMode(false);
			node->setFrameLoop(66,77);

		}
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	if(pos.getDistanceFrom(player) < 50){//die
		if(node->getFrameNr()> 64||node->getFrameNr() <50)
			node->setLoopMode(false);
			node->setFrameLoop(51,65);
		enemyPosition.X = enemyPosition.X;
		enemyPosition.Z = enemyPosition.Z;
	}
	cout<<pos.getDistanceFrom(player)<<endl;
	enemyPosition.Y = land->terrain->getHeight(enemyPosition.X,enemyPosition.Z);
	node->setPosition(enemyPosition);
	node->setRotation(core::vector3df(0,Eangle,0));

}
Post Reply