Example #1
0
        public override void OnEvent(Event evt)
        {
            switch (evt.Type)
            {
            case AnimationEvent.PLAY_ANIMATION:
                var animationEvent = (AnimationEvent)evt;
                resetOnStopped = animationEvent.ResetOnStop;
                loop           = animationEvent.Loops;
                isPlaying      = true;
                break;

            case AnimationEvent.STOP_ANIMATION:
                isPlaying         = false;
                entity[Key_Frame] = 0.0f;
                eventManager.Queue(AnimationEvent.Stopped(entity.ID));
                break;

            case AnimationEvent.PAUSE_ANIMATION:
                isPlaying         = false;
                entity[Key_Frame] = 0.0f;
                eventManager.Queue(AnimationEvent.Stopped(entity.ID));
                break;

            default:
                break;
            }
        }
Example #2
0
        public override void OnUpdate(float deltaTime)
        {
            if (!isPlaying)
            {
                return;
            }

            elapsedTime += deltaTime;
            if (elapsedTime > (1.0f / entity[Key_FrameRate]))
            {
                elapsedTime = 0.0f;
                float frame = entity[Key_Frame];

                if (frame < entity[Key_FrameCount] - 1.0f)
                {
                    entity[Key_Frame] = frame + 1.0f;
                }
                else
                {
                    if (!loop)
                    {
                        isPlaying = false;
                        eventManager.Queue(AnimationEvent.Stopped(entity.ID));
                    }
                    if (resetOnStopped || loop)
                    {
                        entity[Key_Frame] = 0.0f;
                    }
                }
            }
        }