示例#1
0
 public void advance_to_next_animation_inner(float timeElapsed, AnimSequenceNode currAnim, double frameNum, AFrame frame, bool checkFrame, bool firstCheck)
 {
     if (frame != null && checkFrame)
     {
         if (currAnim.Anim.PosFrames.Count > 0)
         {
             if (firstCheck)
             {
                 frame.Subtract(currAnim.get_pos_frame((int)Math.Floor(frameNum)));
             }
             else
             {
                 frame = AFrame.Combine(frame, currAnim.get_pos_frame((int)Math.Floor(frameNum)));
             }
         }
         if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
         {
             apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
         }
     }
 }
示例#2
0
        public void update_internal(float timeElapsed, ref LinkedListNode <AnimSequenceNode> animNode, ref float frameNum, ref AFrame frame)
        {
            var currAnim = animNode.Value;

            var framerate = currAnim.Framerate;
            var frametime = framerate * timeElapsed;

            var lastFrame = (int)Math.Floor(frameNum);

            frameNum += frametime;
            var frameTimeElapsed = 0.0f;
            var animDone         = false;

            if (frametime > 0.0f)
            {
                if (currAnim.get_high_frame() < Math.Floor(frameNum))
                {
                    var frameOffset = frameNum - currAnim.get_high_frame() - 1.0f;
                    if (frameOffset < 0.0f)
                    {
                        frameOffset = 0.0f;
                    }

                    if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                    {
                        frameTimeElapsed = frameOffset / framerate;
                    }

                    frameNum = currAnim.get_high_frame();
                    animDone = true;
                }
                while (Math.Floor(frameNum) > lastFrame)
                {
                    if (frame != null)
                    {
                        if (currAnim.Anim.PosFrames != null)
                        {
                            frame = AFrame.Combine(frame, currAnim.get_pos_frame(lastFrame));
                        }

                        if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                        {
                            apply_physics(frame, 1.0f / framerate, timeElapsed);
                        }
                    }

                    execute_hooks(currAnim.get_part_frame(lastFrame), AnimationHookDir.Forward);
                    lastFrame++;
                }
            }
            else if (frametime < 0.0f)
            {
                if (currAnim.get_low_frame() > Math.Floor(frameNum))
                {
                    var frameOffset = frameNum - currAnim.get_low_frame();
                    if (frameOffset > 0.0f)
                    {
                        frameOffset = 0.0f;
                    }

                    if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                    {
                        frameTimeElapsed = frameOffset / framerate;
                    }

                    frameNum = currAnim.get_low_frame();
                    animDone = true;
                }
                while (Math.Floor(frameNum) < lastFrame)
                {
                    if (frame != null)
                    {
                        if (currAnim.Anim.PosFrames != null)
                        {
                            frame.Subtract(currAnim.get_pos_frame(lastFrame));
                        }

                        if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                        {
                            apply_physics(frame, 1.0f / framerate, timeElapsed);
                        }
                    }

                    execute_hooks(currAnim.get_part_frame(lastFrame), AnimationHookDir.Backward);
                    lastFrame--;
                }
            }
            else
            {
                if (frame != null && Math.Abs(timeElapsed) > PhysicsGlobals.EPSILON)
                {
                    apply_physics(frame, timeElapsed, timeElapsed);
                }
            }

            if (!animDone)
            {
                return;
            }

            if (HookObj != null)
            {
                var node = AnimList.First;
                if (!node.Equals(FirstCyclic))
                {
                    var animDoneHook = new AnimDoneHook();  // static?
                    HookObj.add_anim_hook(animDoneHook);
                }
            }

            advance_to_next_animation(timeElapsed, ref animNode, ref frameNum, ref frame);
            timeElapsed = frameTimeElapsed;

            // loop to next anim
            update_internal(timeElapsed, ref animNode, ref frameNum, ref frame);
        }
示例#3
0
        public void advance_to_next_animation(float timeElapsed, ref LinkedListNode <AnimSequenceNode> animNode, ref float frameNum, ref AFrame frame)
        {
            var currAnim = animNode.Value;

            if (timeElapsed >= 0.0f)
            {
                if (frame != null && currAnim.Framerate < 0.0f)
                {
                    if (currAnim.Anim.PosFrames.Count > 0)
                    {
                        frame.Subtract(currAnim.get_pos_frame((int)frameNum));
                    }
                    if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
                    {
                        apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
                    }
                }
                if (animNode.Next != null)
                {
                    animNode = animNode.Next;
                }
                else
                {
                    animNode = FirstCyclic;
                }

                currAnim = animNode.Value;

                frameNum = currAnim.get_starting_frame();

                if (frame != null && currAnim.Framerate > 0.0f)
                {
                    if (currAnim.Anim.PosFrames.Count > 0)
                    {
                        frame = AFrame.Combine(frame, currAnim.get_pos_frame((int)frameNum));
                    }
                    if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
                    {
                        apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
                    }
                }
            }
            else
            {
                if (frame != null && currAnim.Framerate >= 0.0f)
                {
                    if (currAnim.Anim.PosFrames.Count > 0)
                    {
                        frame.Subtract(currAnim.get_pos_frame((int)frameNum));
                    }
                    if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
                    {
                        apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
                    }
                }
                if (animNode.Previous != null)
                {
                    animNode = animNode.Previous;
                }
                else
                {
                    animNode = animNode.List.Last;
                }

                currAnim = animNode.Value;

                frameNum = currAnim.get_ending_frame();

                if (frame != null && currAnim.Framerate < 0.0f)
                {
                    if (currAnim.Anim.PosFrames.Count > 0)
                    {
                        frame = AFrame.Combine(frame, currAnim.get_pos_frame((int)frameNum));
                    }
                    if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
                    {
                        apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
                    }
                }
            }
        }