Game Development Community

Animated Behavior Problem

by rennie moffat · in iTorque 2D · 02/25/2011 (1:18 pm) · 3 replies

Hi there,
I am attempting to use a behaor to control an enemy, including it's animation. However, using the system below, the animation when called, only plays the first frame, not the entire loop.




Currently this is what I am doing.
Where the owner is an animatedSprite (bigGuyStandingAnimation).


///in onUpdate() 
	if($EnemyWalking == true)	
	{
		if($EnemyWalkingLeft == true)
		{
			$EnemyWalkingRight = false;
		    ///animate walking left
			//set flip
			%this.owner.setFlipX(true);
			///set velocity
			%this.owner.setlinearVelocityX($EnemyVelocity * (-1));
			///playAnimation
			%this.owner.playAnimation(bigGuyWalkingAnimation);
		}
		else if($EnemyWalkingRight == true)
		{
			$EnemyWalkingLeft = false;
			///animate walking left
			//set flip
			%this.owner.setFlipX(false);
			///set velocity
			%this.owner.setlinearVelocityX($EnemyVelocity);
			%this.owner.playAnimation(bigGuyWalkingAnimation);
		}
	}
	else if($EnemyWalking == false)
	{	
		%this.owner.playAnimation(bigGuyStandingAnimation);
		%this.owner.setLinearVelocityX(0);
	}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
02/25/2011 (2:06 pm)
edited.
#2
02/27/2011 (11:54 pm)
How often do that code happen? Everytime that you start playing an animation it starts from the beginning. So if that code is called very often the animation will not have time to play before getting restarted.

When I have had animations I have used the playAnimation function, but with more arguments.

playAnimation(%animation, [%autoRestore = false], [%startFrame = -1], [%mergeTime = false]);
#3
02/28/2011 (4:34 am)
not sure, maybe I should be implementing, getIsAnimationFinished too. Will look into. thanks.