GetNextFrame() public method

public GetNextFrame ( SPRITE_FRAME &nextFrame ) : bool
nextFrame SPRITE_FRAME
return bool
Example #1
0
    /*
     *      // Steps to the next frame of sprite animation
     *      public bool StepAnim(float time)
     *      {
     *              if (curAnim == null)
     *                      return false;
     *
     *              timeSinceLastFrame += time;
     *
     *              framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames);
     *
     *              // If there's nothing to do, return:
     *              if (framesToAdvance < 1)
     *                      return true;
     *
     *              while (framesToAdvance > 0)
     *              {
     *                      if (curAnim.GetNextFrame(ref lowerLeftUV))
     *                              --framesToAdvance;
     *                      else
     *                      {
     *                              // We reached the end of our animation
     *                              if (animCompleteDelegate != null)
     *                                      animCompleteDelegate();
     *
     *                              // Update mesh UVs:
     *                              UpdateUVs();
     *                              PauseAnim();
     *                              animating = false;
     *
     *                              return false;
     *                      }
     *              }
     *
     *              // Update mesh UVs:
     *              UpdateUVs();
     *
     *              timeSinceLastFrame = 0;
     *
     *              return true;
     *      }
     */

    // Steps to the next frame of sprite animation
    public override bool StepAnim(float time)
    {
        if (curAnim == null)
        {
            return(false);
        }

        timeSinceLastFrame += Mathf.Max(0, time);
        //timeSinceLastFrame += time;

        framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames);

        // If there's nothing to do, return:
        if (framesToAdvance < 1)
        {
            return(true);
        }

        //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance;

        while (framesToAdvance > 0)
        {
            if (curAnim.GetNextFrame(ref frameInfo))
            {
                --framesToAdvance;
                timeSinceLastFrame -= timeBetweenAnimFrames;
#if SPRITE_FRAME_DELEGATE
                // Notify the delegate:
                if (framesToAdvance > 0)
                {
                    if (animFrameDelegate != null)
                    {
                        animFrameDelegate(this, curAnim.GetCurPosition());
                    }
                }
#endif
            }
            else
            {
                // We reached the end of our animation

                // See if we should revert to a static appearance,
                // default anim, or do nothing, etc:
                switch (curAnim.onAnimEnd)
                {
                case UVAnimation.ANIM_END_ACTION.Do_Nothing:
                    PauseAnim();

                    // Update mesh UVs:
                    uvRect = frameInfo.uvs;
                    SetBleedCompensation();

                    // Resize if selected:
                    if (autoResize || pixelPerfect)
                    {
                        CalcSize();
                    }
                    break;

                case UVAnimation.ANIM_END_ACTION.Revert_To_Static:
                    RevertToStatic();
                    curAnim = null;
                    break;

                case UVAnimation.ANIM_END_ACTION.Play_Default_Anim:
                    // Notify the delegates:
#if SPRITE_FRAME_DELEGATE
                    if (animFrameDelegate != null)
                    {
                        animFrameDelegate(this, curAnim.GetCurPosition());
                    }
#endif
                    if (animCompleteDelegate != null)
                    {
                        animCompleteDelegate(this);
                    }

                    // Play the default animation:
                    PlayAnim(defaultAnim);
                    return(false);

                case UVAnimation.ANIM_END_ACTION.Hide:
                    Hide(true);
                    break;

                case UVAnimation.ANIM_END_ACTION.Deactivate:
                    gameObject.active = false;
                    break;

                case UVAnimation.ANIM_END_ACTION.Destroy:
                    // Notify the delegates:
#if SPRITE_FRAME_DELEGATE
                    if (animFrameDelegate != null)
                    {
                        animFrameDelegate(this, curAnim.GetCurPosition());
                    }
#endif
                    if (animCompleteDelegate != null)
                    {
                        animCompleteDelegate(this);
                    }

                    Delete();
                    Destroy(gameObject);
                    break;
                }

                // Notify the delegates:
#if SM2_FRAME_DELEGATE
                if (animFrameDelegate != null)
                {
                    animFrameDelegate(this, curAnim.GetCurPosition());
                }
#endif
                if (animCompleteDelegate != null)
                {
                    animCompleteDelegate(this);
                }

                // Check to see if we are still animating
                // before setting the curAnim to null.
                // Animating should be turned off if
                // PauseAnim() was called above, or if we
                // reverted to static.  But it could have
                // been turned on again by the
                // animCompleteDelegate.
                if (!animating)
                {
                    curAnim = null;
                }

                return(false);
            }
        }

#if SM2_FRAME_DELEGATE
        if (animFrameDelegate != null)
        {
            animFrameDelegate(this, curAnim.GetCurPosition());
        }
#endif

        // Update mesh UVs:
        uvRect = frameInfo.uvs;
        SetBleedCompensation();

        // Resize if selected:
        if (autoResize || pixelPerfect)
        {
            CalcSize();
        }

        //timeSinceLastFrame = 0;

        return(true);
    }
Example #2
0
    /*
     *      // Steps to the next frame of sprite animation
     *      public bool StepAnim(float time)
     *      {
     *              if (curAnim == null)
     *                      return false;
     *
     *              timeSinceLastFrame += time;
     *
     *              framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames);
     *
     *              // If there's nothing to do, return:
     *              if (framesToAdvance < 1)
     *                      return true;
     *
     *              while (framesToAdvance > 0)
     *              {
     *                      if (curAnim.GetNextFrame(ref lowerLeftUV))
     *                              --framesToAdvance;
     *                      else
     *                      {
     *                              // We reached the end of our animation
     *                              if (animCompleteDelegate != null)
     *                                      animCompleteDelegate();
     *
     *                              // Update mesh UVs:
     *                              UpdateUVs();
     *                              PauseAnim();
     *                              animating = false;
     *
     *                              return false;
     *                      }
     *              }
     *
     *              // Update mesh UVs:
     *              UpdateUVs();
     *
     *              timeSinceLastFrame = 0;
     *
     *              return true;
     *      }
     */

    // Steps to the next frame of sprite animation
    public override bool StepAnim(float time)
    {
        if (curAnim == null)
        {
            return(false);
        }

        timeSinceLastFrame += Mathf.Max(0, time);
        //timeSinceLastFrame += time;

        framesToAdvance = (timeSinceLastFrame / timeBetweenAnimFrames);

        // If there's nothing to do, return:
        if (framesToAdvance < 1)
        {
            if (crossfadeFrames)
            {
                SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance)));
            }
            return(true);
        }

        //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance;

        while (framesToAdvance >= 1f)
        {
            if (curAnim.GetNextFrame(ref frameInfo))
            {
#if SPRITE_FRAME_DELEGATE
                // Notify the delegate:
                if (framesToAdvance >= 1f)
                {
                    if (animFrameDelegate != null)
                    {
                        animFrameDelegate(this, curAnim.GetCurPosition());
                    }
                }
#endif
                framesToAdvance    -= 1f;
                timeSinceLastFrame -= timeBetweenAnimFrames;
            }
            else
            {
                // We reached the end of our animation
                if (crossfadeFrames)
                {
                    SetColor(Color.white);
                }

                // See if we should revert to a static appearance,
                // default anim, or do nothing, etc:
                switch (curAnim.onAnimEnd)
                {
                case UVAnimation.ANIM_END_ACTION.Do_Nothing:
                    PauseAnim();

                    // Update mesh UVs:
                    uvRect = frameInfo.uvs;
                    SetBleedCompensation();

                    // Resize if selected:
                    if (autoResize || pixelPerfect)
                    {
                        CalcSize();
                    }
                    break;

                case UVAnimation.ANIM_END_ACTION.Revert_To_Static:
                    RevertToStatic();
                    curAnim = null;
                    break;

                case UVAnimation.ANIM_END_ACTION.Play_Default_Anim:
                    // Notify the delegates:

                    /*
                     #if SPRITE_FRAME_DELEGATE
                     *                                              if (animFrameDelegate != null)
                     *                                                      animFrameDelegate(this, curAnim.GetCurPosition());
                     #endif
                     */
                    if (animCompleteDelegate != null)
                    {
                        animCompleteDelegate(this);
                    }

                    // Play the default animation:
                    PlayAnim(defaultAnim);
                    return(false);

                case UVAnimation.ANIM_END_ACTION.Hide:
                    Hide(true);
                    break;

                case UVAnimation.ANIM_END_ACTION.Deactivate:
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
                    gameObject.SetActive(false);
#else
                    gameObject.active = false;
#endif
                    break;

                case UVAnimation.ANIM_END_ACTION.Destroy:
                    // Notify the delegates:

                    /*
                     #if SPRITE_FRAME_DELEGATE
                     *                                              if (animFrameDelegate != null)
                     *                                                      animFrameDelegate(this, curAnim.GetCurPosition());
                     #endif
                     */
                    if (animCompleteDelegate != null)
                    {
                        animCompleteDelegate(this);
                    }

                    Delete();
                    Destroy(gameObject);
                    break;
                }

                // Notify the delegates:

                /*
                 #if SM2_FRAME_DELEGATE
                 *                      if (animFrameDelegate != null)
                 *                              animFrameDelegate(this, curAnim.GetCurPosition());
                 #endif
                 */
                if (animCompleteDelegate != null)
                {
                    animCompleteDelegate(this);
                }

                // Check to see if we are still animating
                // before setting the curAnim to null.
                // Animating should be turned off if
                // PauseAnim() was called above, or if we
                // reverted to static.  But it could have
                // been turned on again by the
                // animCompleteDelegate.
                if (!animating)
                {
                    curAnim = null;
                }

                return(false);
            }
        }

        // Cross-fade to the next frame:
        if (crossfadeFrames)
        {
            UVAnimation curClip      = curAnim.GetCurrentClip();
            int         curClipNum   = curAnim.GetCurClipNum();
            int         curFrame     = curClip.GetCurPosition();
            int         multiStepDir = curAnim.StepDirection;
            int         clipStepDir  = curClip.StepDirection;

            curAnim.GetNextFrame(ref nextFrameInfo);

            Vector2[] uvs2   = m_spriteMesh.uvs2;
            Rect      nextUV = nextFrameInfo.uvs;
            uvs2[0].x = nextUV.xMin; uvs2[0].y = nextUV.yMax;
            uvs2[1].x = nextUV.xMin; uvs2[1].y = nextUV.yMin;
            uvs2[2].x = nextUV.xMax; uvs2[2].y = nextUV.yMin;
            uvs2[3].x = nextUV.xMax; uvs2[3].y = nextUV.yMax;

            // Undo our advance:
            curAnim.SetCurClipNum(curClipNum);
            curClip.SetCurrentFrame(curFrame);
            curAnim.StepDirection = multiStepDir;
            curClip.StepDirection = clipStepDir;

            SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance)));
        }

        /*
         #if SM2_FRAME_DELEGATE
         *              if (animFrameDelegate != null)
         *                      animFrameDelegate(this, curAnim.GetCurPosition());
         #endif
         */
        // Update mesh UVs:
        uvRect = frameInfo.uvs;
        SetBleedCompensation();

        // Resize if selected:
        if (autoResize || pixelPerfect)
        {
            CalcSize();
        }

        //timeSinceLastFrame = 0;

        return(true);
    }