protected internal override void step(float xOffset, float yOffset)
        {
            int firstLastSpeed  = first.frameSpeed;
            int secondLastSpeed = second.frameSpeed;

            //int speed = this.frameSpeed;
            //if(this.interpolateSpeed)	speed = (int)this.interpolate(first.frameSpeed, second.frameSpeed, 0, 1, this.weight);
            //this.first.frameSpeed = speed;
            //this.second.frameSpeed = speed;
            this.moddedBones   = (this.weight <= 0.5f) ? this.first.moddedBones : this.second.moddedBones;
            this.moddedObjects = (this.weight <= 0.5f) ? this.first.moddedObjects : this.second
                                 .moddedObjects;
            this.currenObjectsToDraw = System.Math.Max(first.currenObjectsToDraw, second.currenObjectsToDraw
                                                       );
            this.currentBonesToAnimate = System.Math.Max(first.currentBonesToAnimate, second.
                                                         currentBonesToAnimate);
            if (this.updatePlayers)
            {
                this.first.update(xOffset, yOffset);
                this.second.update(xOffset, yOffset);
            }
            Com.Brashmonkey.Spriter.animation.SpriterKeyFrame key1 = (first.transitionFixed) ?
                                                                     first.lastFrame : first.lastTempFrame;
            Com.Brashmonkey.Spriter.animation.SpriterKeyFrame key2 = (second.transitionFixed)
                                 ? second.lastFrame : second.lastTempFrame;
            this.transformBones(key1, key2, xOffset, yOffset);
            this.transformObjects(first.lastFrame, second.lastFrame, xOffset, yOffset);
            this.first.frameSpeed  = firstLastSpeed;
            this.second.frameSpeed = secondLastSpeed;
        }
Ejemplo n.º 2
0
 /// <summary>Sets the animationIndex for this to the given animationIndex.</summary>
 /// <remarks>
 /// Sets the animationIndex for this to the given animationIndex.
 /// This method can make sure that the switching between to animations is smooth.
 /// By setting transitionSpeed and transitionSteps to appropriate values, you can have nice transitions between two animations.
 /// Setting transitionSpeed to 1 and transitionSteps to 20 means, that this player will need 20 steps to translate the current animation to the given one.
 /// </remarks>
 /// <param name="animationIndex">
 /// Index of animation to set. Get the index with
 /// <see cref="getAnimationIndexByName(string)">getAnimationIndexByName(string)</see>
 /// .
 /// </param>
 /// <param name="transitionSpeed">Speed for the switch between the current animation and the one which has been set.
 ///     </param>
 /// <param name="transitionSteps">Steps needed for the transition</param>
 /// <exception cref="System.Exception"></exception>
 public virtual void setAnimatioIndex(int animationIndex, int transitionSpeed, int
                                      transitionSteps)
 {
     if (animationIndex >= this.entity.getAnimation().Count || animationIndex < 0)
     {
         throw new System.Exception("The given animation index does not exist: " + animationIndex
                                    + "\n" + "Index range goes from 0 to " + (this.entity.getAnimation().Count - 1)
                                    );
     }
     if (this.animationIndex != animationIndex)
     {
         if (this.transitionFixed)
         {
             this.lastRealFrame       = this.lastFrame;
             this.transitionFixed     = false;
             this.transitionTempFixed = true;
         }
         else
         {
             this.lastRealFrame       = this.lastTempFrame;
             this.transitionTempFixed = false;
             this.transitionFixed     = true;
         }
         this.transitionSpeed = transitionSpeed;
         this.fixMaxSteps     = transitionSteps;
         this.lastRealFrame.setTime(this.frame + 1);
         this.animation = this.animations[animationIndex];
         this.animation.frames[0].setTime(this.frame + 1 + this.fixMaxSteps);
         this.currentKey     = 0;
         this.fixCounter     = 0;
         this.animationIndex = animationIndex;
     }
 }
Ejemplo n.º 3
0
 /// <summary>Constructs a new SpriterPlayer object which animates the given Spriter entity.
 ///     </summary>
 /// <remarks>Constructs a new SpriterPlayer object which animates the given Spriter entity.
 ///     </remarks>
 /// <param name="data">
 ///
 /// <see cref="SpriterData">SpriterData
 ///     </see>
 /// which provides a method to load all needed data to animate. See
 /// <see cref="Spriter#getSpriter(String,com.spriter.file.FileLoader)">Spriter#getSpriter(String,com.spriter.file.FileLoader)
 ///     </see>
 /// for mor information.
 /// </param>
 /// <param name="entityIndex">The entity which should be handled by this player.</param>
 /// <param name="loader">The loader which has loaded all necessary sprites for the scml file.
 ///     </param>
 public SpriterPlayer(SpriterData data, Entity
                      entity, FileLoader loader) : base(loader, null)
 {
     this.entity = entity;
     this.frame  = 0;
     if (!alreadyLoaded(entity))
     {
         this.animations = SpriterKeyFrameProvider.generateKeyFramePool(data, entity);
         loaded.Add(entity, this);
     }
     else
     {
         this.animations = loaded[entity].animations;
     }
     this.generateData();
     this.animation     = this.animations[0];
     this.firstKeyFrame = this.animation.frames[0];
     this.update(0, 0);
 }
Ejemplo n.º 4
0
        protected internal override void step(float xOffset, float yOffset)
        {
            //Fetch information
            IList <Com.Brashmonkey.Spriter.animation.SpriterKeyFrame
                   > frameList = this.animation.frames;

            if (this.transitionFixed && this.transitionTempFixed)
            {
                firstKeyFrame  = frameList[this.currentKey];
                secondKeyFrame = frameList[(this.currentKey + 1) % frameList.Count];
                //Update
                this.frame += this.frameSpeed;
                if (this.frame >= this.animation.length)
                {
                    this.frame      = 0;
                    this.currentKey = 0;
                    firstKeyFrame   = frameList[this.currentKey];
                    secondKeyFrame  = frameList[(this.currentKey + 1) % frameList.Count];
                }
                if (this.frame > secondKeyFrame.getTime() && this.frameSpeed >= 0)
                {
                    this.currentKey = (this.currentKey + 1) % frameList.Count;
                }
                else
                {
                    if (this.frame < firstKeyFrame.getTime())
                    {
                        if (this.frame < 0)
                        {
                            this.frame      = this.animation.length;
                            this.currentKey = frameList.Count - 1;
                            firstKeyFrame   = frameList[frameList.Count - 1];
                            secondKeyFrame  = frameList[0];
                        }
                        else
                        {
                            this.currentKey = ((this.currentKey - 1) + frameList.Count) % frameList.Count;
                        }
                    }
                }
            }
            else
            {
                firstKeyFrame  = frameList[0];
                secondKeyFrame = this.lastRealFrame;
                float temp = (float)(this.fixCounter) / (float)this.fixMaxSteps;
                this.frame      = this.lastRealFrame.getTime() + (long)(this.fixMaxSteps * temp);
                this.fixCounter = System.Math.Min(this.fixCounter + this.transitionSpeed, this.fixMaxSteps
                                                  );
                //Update
                if (this.fixCounter == this.fixMaxSteps)
                {
                    this.frame      = 0;
                    this.fixCounter = 0;
                    if (this.lastRealFrame.Equals(this.lastFrame))
                    {
                        this.transitionFixed = true;
                    }
                    else
                    {
                        this.transitionTempFixed = true;
                    }
                    firstKeyFrame.setTime(0);
                }
            }
            //Interpolate
            this.currenObjectsToDraw   = firstKeyFrame.getObjects().Length;
            this.currentBonesToAnimate = firstKeyFrame.getBones().Length;
            this.transformBones(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
            this.transformObjects(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
        }
Ejemplo n.º 5
0
 protected internal override void step(float xOffset, float yOffset)
 {
     //Fetch information
     IList<Com.Brashmonkey.Spriter.animation.SpriterKeyFrame
         > frameList = this.animation.frames;
     if (this.transitionFixed && this.transitionTempFixed)
     {
         firstKeyFrame = frameList[this.currentKey];
         secondKeyFrame = frameList[(this.currentKey + 1) % frameList.Count];
         //Update
         this.frame += this.frameSpeed;
         if (this.frame >= this.animation.length)
         {
             this.frame = 0;
             this.currentKey = 0;
             firstKeyFrame = frameList[this.currentKey];
             secondKeyFrame = frameList[(this.currentKey + 1) % frameList.Count];
         }
         if (this.frame > secondKeyFrame.getTime() && this.frameSpeed >= 0)
         {
             this.currentKey = (this.currentKey + 1) % frameList.Count;
         }
         else
         {
             if (this.frame < firstKeyFrame.getTime())
             {
                 if (this.frame < 0)
                 {
                     this.frame = this.animation.length;
                     this.currentKey = frameList.Count - 1;
                     firstKeyFrame = frameList[frameList.Count - 1];
                     secondKeyFrame = frameList[0];
                 }
                 else
                 {
                     this.currentKey = ((this.currentKey - 1) + frameList.Count) % frameList.Count;
                 }
             }
         }
     }
     else
     {
         firstKeyFrame = frameList[0];
         secondKeyFrame = this.lastRealFrame;
         float temp = (float)(this.fixCounter) / (float)this.fixMaxSteps;
         this.frame = this.lastRealFrame.getTime() + (long)(this.fixMaxSteps * temp);
         this.fixCounter = System.Math.Min(this.fixCounter + this.transitionSpeed, this.fixMaxSteps
             );
         //Update
         if (this.fixCounter == this.fixMaxSteps)
         {
             this.frame = 0;
             this.fixCounter = 0;
             if (this.lastRealFrame.Equals(this.lastFrame))
             {
                 this.transitionFixed = true;
             }
             else
             {
                 this.transitionTempFixed = true;
             }
             firstKeyFrame.setTime(0);
         }
     }
     //Interpolate
     this.currenObjectsToDraw = firstKeyFrame.getObjects().Length;
     this.currentBonesToAnimate = firstKeyFrame.getBones().Length;
     this.transformBones(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
     this.transformObjects(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
 }
Ejemplo n.º 6
0
        /// <summary>Sets the animationIndex for this to the given animationIndex.</summary>
        /// <remarks>
        /// Sets the animationIndex for this to the given animationIndex.
        /// This method can make sure that the switching between to animations is smooth.
        /// By setting transitionSpeed and transitionSteps to appropriate values, you can have nice transitions between two animations.
        /// Setting transitionSpeed to 1 and transitionSteps to 20 means, that this player will need 20 steps to translate the current animation to the given one.
        /// </remarks>
        /// <param name="animationIndex">
        /// Index of animation to set. Get the index with
        /// <see cref="getAnimationIndexByName(string)">getAnimationIndexByName(string)</see>
        /// .
        /// </param>
        /// <param name="transitionSpeed">Speed for the switch between the current animation and the one which has been set.
        /// 	</param>
        /// <param name="transitionSteps">Steps needed for the transition</param>
        /// <exception cref="System.Exception"></exception>
        public virtual void setAnimatioIndex(int animationIndex, int transitionSpeed, int
			 transitionSteps)
        {
            if (animationIndex >= this.entity.getAnimation().Count || animationIndex < 0)
            {
                throw new System.Exception("The given animation index does not exist: " + animationIndex
                     + "\n" + "Index range goes from 0 to " + (this.entity.getAnimation().Count - 1)
                    );
            }
            if (this.animationIndex != animationIndex)
            {
                if (this.transitionFixed)
                {
                    this.lastRealFrame = this.lastFrame;
                    this.transitionFixed = false;
                    this.transitionTempFixed = true;
                }
                else
                {
                    this.lastRealFrame = this.lastTempFrame;
                    this.transitionTempFixed = false;
                    this.transitionFixed = true;
                }
                this.transitionSpeed = transitionSpeed;
                this.fixMaxSteps = transitionSteps;
                this.lastRealFrame.setTime(this.frame + 1);
                this.animation = this.animations[animationIndex];
                this.animation.frames[0].setTime(this.frame + 1 + this.fixMaxSteps);
                this.currentKey = 0;
                this.fixCounter = 0;
                this.animationIndex = animationIndex;
            }
        }
Ejemplo n.º 7
0
        /// <summary>Constructs a new SpriterPlayer object which animates the given Spriter entity.
        /// 	</summary>
        /// <remarks>Constructs a new SpriterPlayer object which animates the given Spriter entity.
        /// 	</remarks>
        /// <param name="data">
        /// 
        /// <see cref="SpriterData">SpriterData
        /// 	</see>
        /// which provides a method to load all needed data to animate. See
        /// <see cref="Spriter#getSpriter(String,com.spriter.file.FileLoader)">Spriter#getSpriter(String,com.spriter.file.FileLoader)
        /// 	</see>
        /// for mor information.
        /// </param>
        /// <param name="entityIndex">The entity which should be handled by this player.</param>
        /// <param name="loader">The loader which has loaded all necessary sprites for the scml file.
        /// 	</param>
        public SpriterPlayer(SpriterData data, Entity
			 entity, FileLoader loader)
            : base(loader, null)
        {
            this.entity = entity;
            this.frame = 0;
            if (!alreadyLoaded(entity))
            {
                this.animations = SpriterKeyFrameProvider.generateKeyFramePool(data, entity);
                loaded.Add(entity, this);
            }
            else
            {
                this.animations = loaded[entity].animations;
            }
            this.generateData();
            this.animation = this.animations[0];
            this.firstKeyFrame = this.animation.frames[0];
            this.update(0, 0);
        }