Ejemplo n.º 1
0
        /*
         * returns "true", if the animation was changed
         * returns "false", if the animation is already playing or not set
         */
        public virtual bool setCurrentAnimation(EMovementState newState, bool interrupt)
        {
            if (currentState == newState)
                return false;
            else
                currentState = newState;

            if (interrupt)
            {
                print("anim interrupted");
                // clear pending anim, if set before
                bHasPendingAnimation = false;
                pendingAnim = null;
                // switch to new animation directly
                currentAnim = getSpriteAnimation(newState);
                currentAnim.startAnimation();
                framesPerSecond = currentAnim.framesPerSecond;
            }
            else
            {
                // check, if we already have a pending animation
                // in this case, we do not need to call "end animation" again and just override pendingAnim
                if (!bHasPendingAnimation)
                {
                    print("made Pending");
                    bHasPendingAnimation = true;
                    currentAnim.endAnimation();
                }

                // remember the next animation
                pendingAnim = getSpriteAnimation(newState);
            }

            return true;
        }
Ejemplo n.º 2
0
 void Awake()
 {
     spRenderer = GetComponent<SpriteRenderer>();
     if (IdleAnim == null) IdleAnim = this.gameObject.AddComponent<SpriteAnimation>();
     if (WalkAnim == null) WalkAnim = this.gameObject.AddComponent<SpriteAnimation>();
     if (RunAnim == null)  RunAnim = this.gameObject.AddComponent<SpriteAnimation>();
     if (IdleAnim == null) JumpUpAnim = this.gameObject.AddComponent<SpriteAnimation>();
     if (IdleAnim == null) JumpForwAnim = this.gameObject.AddComponent<SpriteAnimation>();
     if (IdleAnim == null) JumpBackAnim = this.gameObject.AddComponent<SpriteAnimation>();
 }
Ejemplo n.º 3
0
 void Update()
 {
     print(currentState);
     if ((Time.time - lastFrameUpdateTime) * framesPerSecond >= 1.0f)
     {
         if (bHasPendingAnimation && currentAnim.hasFinishedEndAnimation())
         {
             print("switch to pending anim");
             Debug.Assert(pendingAnim != null, "Animator is pending, but has not pending animation set!");
             bHasPendingAnimation = false;
             currentAnim = pendingAnim;
             pendingAnim = null; // clear, to be sure
             currentAnim.startAnimation();
             framesPerSecond = currentAnim.framesPerSecond;
         }
         // get the next frame
         lastFrameUpdateTime = Time.time;
         spRenderer.flipX = lookLeft;
         spRenderer.sprite = currentAnim.getNextFrame();
     }
 }
Ejemplo n.º 4
0
 void Start()
 {
     currentAnim = IdleAnim;
     spRenderer.flipX = lookLeft;
     spRenderer.sprite = currentAnim.startAnimation();
     framesPerSecond = currentAnim.framesPerSecond;
     lastFrameUpdateTime = Time.time;
 }