Determine Animation is done

TravisBayTravisBay USMember

So, I am having an issue, where the animation won't play out all the way because it jumps right to end of scene. So my "work around" is to add a timer.

 void CheckCollision()
        {
            bool hit = floorSprite.BoundingBoxTransformedToParent.IntersectsRect(fallManSprite.BoundingBoxTransformedToParent);

            if (hit)
            {
                ExplodeAsync(fallManSprite.Position);
                RemoveChild(floorSprite);
                gameDuration = 60f;
            }
        }

game duration is the timer.

Then I routinely check if it is end of the game:

  bool CheckEndGame()
        {
            if (gameDuration == 0)
            {
                return true;
            }
            return false;
        }

Then in my game logic:

 void RunGameLogic(float frameTimeInSeconds)
        {
            var bounds = VisibleBoundsWorldspace;
            var worldYMin = bounds.MinY;
            var worldYMax = bounds.MaxY;

            floorYVelocity += (float)0.01 * gravity;
            if (gameDuration > 0)
            {
                gameDuration -= 1;
            }
            if (floorSprite.PositionY > worldYMax)
            {
                RemoveChild(floorSprite, true);
                floorSprite.Dispose();
                floorSprite = null;
                floorSprite = new CCSprite("FloorBarrierTransparent");
                AddChild(floorSprite);
                ResetPositionAndVelocity(bounds);
                plateformsMissed += 1;
                labelPlatformMissedValue.Text = plateformsMissed.ToString();
            }
            else
            {

                floorSprite.PositionY += floorYVelocity * (float)0.01;
            }
            if (CheckEndGame())
            {
                EndGame();
            }
        }

Does anyone have a good way to determine when an animation is done playing? I am guessing this is the only way.....but it would be nice if there was a built in method that I was overlooking.

Tagged:
Sign In or Register to comment.