Beispiel #1
0
 public virtual void tweenObjects(com.brashmonkey.spriter.animation.SpriterAnimation
                                  animation)
 {
     foreach (System.Collections.Generic.KeyValuePair <com.brashmonkey.spriter.objects.SpriterObject
                                                       , int> entry in objectsToTween.EntrySet())
     {
         com.brashmonkey.spriter.objects.SpriterObject     toTween = entry.Key;
         com.brashmonkey.spriter.animation.SpriterKeyFrame frame   = animation.frames[entry.
                                                                                      Value];
         long time = frame.getTime();
         com.brashmonkey.spriter.animation.SpriterKeyFrame currentFrame = animation.getPreviousFrameForObject
                                                                              (toTween, time);
         com.brashmonkey.spriter.animation.SpriterKeyFrame nextFrame = animation.getNextFrameFor
                                                                           (toTween, currentFrame, 1);
         if (nextFrame != currentFrame)
         {
             com.brashmonkey.spriter.objects.SpriterObject object1 = currentFrame.getObjectFor
                                                                         (toTween);
             com.brashmonkey.spriter.objects.SpriterObject object2 = nextFrame.getObjectFor(toTween
                                                                                            );
             this.interpolateSpriterObject(toTween, object1, object2, currentFrame.getTime(),
                                           nextFrame.getTime(), time);
         }
         com.brashmonkey.spriter.objects.SpriterObject[] objects = new com.brashmonkey.spriter.objects.SpriterObject
                                                                   [frame.getObjects().Length + 1];
         for (int i = 0; i < objects.Length - 1; i++)
         {
             objects[i] = frame.getObjects()[i];
         }
         objects[objects.Length - 1] = toTween;
         frame.setObjects(objects);
     }
 }
Beispiel #2
0
        public virtual com.brashmonkey.spriter.animation.SpriterKeyFrame getNextFrameFor(
            com.brashmonkey.spriter.objects.SpriterAbstractObject @object, com.brashmonkey.spriter.animation.SpriterKeyFrame
            currentFrame, int direction)
        {
            com.brashmonkey.spriter.animation.SpriterKeyFrame nextFrame = null;
            int  cnt    = 0;
            bool isBone = @object is com.brashmonkey.spriter.objects.SpriterBone;

            for (int j = (currentFrame.getId() + direction + this.numberOfFrames()) % this.numberOfFrames();
                 nextFrame == null && cnt < this.numberOfFrames(); j = (j + direction + this.numberOfFrames()) %
                                                                       this.numberOfFrames(), cnt++)
            {
                com.brashmonkey.spriter.animation.SpriterKeyFrame frame = this.frames[j];
                bool contains = (isBone) ? frame.containsBone((com.brashmonkey.spriter.objects.SpriterBone
                                                               )@object) : frame.containsObject((com.brashmonkey.spriter.objects.SpriterObject)
                                                                                                @object);
                if (contains)
                {
                    com.brashmonkey.spriter.objects.SpriterAbstractObject objectInFrame;
                    if (isBone)
                    {
                        objectInFrame = frame.getBoneFor((com.brashmonkey.spriter.objects.SpriterBone)@object);
                    }
                    else
                    {
                        objectInFrame = frame.getObjectFor((com.brashmonkey.spriter.objects.SpriterObject)@object);
                    }
                    if (@object.equals(objectInFrame))
                    {
                        nextFrame = frame;
                    }
                }
            }
            return(nextFrame);
        }
 /// <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;
     }
 }
Beispiel #4
0
 public virtual void tweenBones(com.brashmonkey.spriter.animation.SpriterAnimation
                                animation)
 {
     foreach (System.Collections.Generic.KeyValuePair <com.brashmonkey.spriter.objects.SpriterBone
                                                       , int> entry in bonesToTween.EntrySet())
     {
         com.brashmonkey.spriter.objects.SpriterBone       toTween = entry.Key;
         com.brashmonkey.spriter.animation.SpriterKeyFrame frame   = animation.frames[entry.
                                                                                      Value];
         long time = frame.getTime();
         com.brashmonkey.spriter.animation.SpriterKeyFrame currentFrame = animation.getPreviousFrameForBone
                                                                              (toTween, time);
         com.brashmonkey.spriter.animation.SpriterKeyFrame nextFrame = animation.getNextFrameFor
                                                                           (toTween, currentFrame, 1);
         if (nextFrame != currentFrame)
         {
             com.brashmonkey.spriter.objects.SpriterBone bone1 = currentFrame.getBoneFor(toTween
                                                                                         );
             com.brashmonkey.spriter.objects.SpriterBone bone2 = nextFrame.getBoneFor(toTween);
             this.interpolateAbstractObject(toTween, bone1, bone2, currentFrame.getTime(), nextFrame
                                            .getTime(), time);
         }
         com.brashmonkey.spriter.objects.SpriterBone[] bones = new com.brashmonkey.spriter.objects.SpriterBone
                                                               [frame.getBones().Length + 1];
         for (int i = 0; i < bones.Length - 1; i++)
         {
             bones[i] = frame.getBones()[i];
         }
         bones[bones.Length - 1] = toTween;
         frame.setBones(bones);
     }
 }
        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;
            if (this.weight == 0)
            {
                this.first.update(xOffset, yOffset);
                this.instructions          = this.first.instructions;
                this.currenObjectsToDraw   = first.currenObjectsToDraw;
                this.currentBonesToAnimate = first.currentBonesToAnimate;
            }
            else
            {
                if (this.weight == 1)
                {
                    this.second.update(xOffset, yOffset);
                    this.instructions          = this.second.instructions;
                    this.currenObjectsToDraw   = second.currenObjectsToDraw;
                    this.currentBonesToAnimate = second.currentBonesToAnimate;
                }
                else
                {
                    this.currenObjectsToDraw   = System.Math.Min(first.currenObjectsToDraw, second.currenObjectsToDraw);
                    this.currentBonesToAnimate = System.Math.Min(first.currentBonesToAnimate, second.
                                                                 currentBonesToAnimate);
                    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(key1, key2, xOffset, yOffset);
                }
            }
            this.first.frameSpeed  = firstLastSpeed;
            this.second.frameSpeed = secondLastSpeed;
        }
Beispiel #6
0
 /// <summary>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time.
 ///     </summary>
 /// <remarks>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time.
 ///     </remarks>
 /// <param name="time"></param>
 /// <returns>A keyframe object which has a smaller or equal starting time than the given time.
 ///     </returns>
 public virtual com.brashmonkey.spriter.animation.SpriterKeyFrame getPreviousFrame
     (long time)
 {
     com.brashmonkey.spriter.animation.SpriterKeyFrame frame = null;
     foreach (com.brashmonkey.spriter.animation.SpriterKeyFrame key in this.frames)
     {
         if (key.getTime() <= time)
         {
             frame = key;
         }
         else
         {
             break;
         }
     }
     return(frame);
 }
 /// <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="com.discobeard.spriter.dom.SpriterData">com.discobeard.spriter.dom.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(com.discobeard.spriter.dom.SpriterData data, com.discobeard.spriter.dom.Entity
                      entity, com.brashmonkey.spriter.file.FileLoader loader) : base(loader, null)
 {
     this.entity = entity;
     this.frame  = 0;
     if (!alreadyLoaded(entity))
     {
         this.animations = com.brashmonkey.spriter.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);
 }
Beispiel #8
0
 /// <summary>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time and contains the given object.
 ///     </summary>
 /// <remarks>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time and contains the given object.
 ///     </remarks>
 /// <param name="object"></param>
 /// <param name="time"></param>
 /// <returns>A keyframe object which has a smaller or equal starting time than the given time and contains the given object.
 ///     </returns>
 public virtual com.brashmonkey.spriter.animation.SpriterKeyFrame getPreviousFrameForObject
     (com.brashmonkey.spriter.objects.SpriterObject @object, long time)
 {
     com.brashmonkey.spriter.animation.SpriterKeyFrame frame = null;
     foreach (com.brashmonkey.spriter.animation.SpriterKeyFrame key in this.frames)
     {
         if (!key.containsObject(@object))
         {
             continue;
         }
         if (key.getTime() <= time)
         {
             frame = key;
         }
         else
         {
             break;
         }
     }
     return(frame);
 }
        //import com.brashmonkey.spriter.converters.SpriterObjectConverter;
        //import com.discobeard.spriter.dom.AnimationObject;
        //final private SpriterObjectConverter objectConverter = new SpriterObjectConverter();
        public virtual com.brashmonkey.spriter.animation.SpriterAnimation buildAnimation(
			com.discobeard.spriter.dom.Animation animation)
        {
            com.discobeard.spriter.dom.MainLine mainline = animation.getMainline();
            System.Collections.Generic.IList<com.discobeard.spriter.dom.TimeLine> timeLines =
                animation.getTimeline();
            System.Collections.Generic.IList<com.discobeard.spriter.dom.Key> keyFrames = mainline
                .getKey();
            bonesToTween = new System.Collections.Generic.Dictionary<com.brashmonkey.spriter.objects.SpriterBone
                , int>();
            objectsToTween = new System.Collections.Generic.Dictionary<com.brashmonkey.spriter.objects.SpriterObject
                , int>();
            com.brashmonkey.spriter.animation.SpriterAnimation spriterAnimation = new com.brashmonkey.spriter.animation.SpriterAnimation
                (animation.getId(), animation.getName(), animation.getLength());
            for (int k = 0; k < keyFrames.Count; k++)
            {
                com.discobeard.spriter.dom.Key mainlineKey = keyFrames[k];
                System.Collections.Generic.IList<com.brashmonkey.spriter.objects.SpriterObject> tempObjects
                     = new System.Collections.Generic.List<com.brashmonkey.spriter.objects.SpriterObject
                    >();
                System.Collections.Generic.IList<com.brashmonkey.spriter.objects.SpriterBone> tempBones
                     = new System.Collections.Generic.List<com.brashmonkey.spriter.objects.SpriterBone
                    >();
                com.brashmonkey.spriter.animation.SpriterKeyFrame frame = new com.brashmonkey.spriter.animation.SpriterKeyFrame
                    ();
                frame.setTime(mainlineKey.getTime());
                frame.setId(mainlineKey.getId());
                foreach (com.discobeard.spriter.dom.BoneRef boneRef in mainlineKey.getBoneRef())
                {
                    com.discobeard.spriter.dom.TimeLine timeline = timeLines[boneRef.getTimeline()];
                    com.discobeard.spriter.dom.Key timelineKey = timeline.getKey()[boneRef.getKey()];
                    com.brashmonkey.spriter.objects.SpriterBone bone = boneMerger.merge(boneRef, timelineKey
                        );
                    bone.setName(timeline.getName());
                    if (mainlineKey.getTime() != timelineKey.getTime())
                    {
                        bonesToTween.Add(bone, k);
                    }
                    else
                    {
                        tempBones.Add(bone);
                    }
                }
                //}
                foreach (com.discobeard.spriter.dom.AnimationObjectRef objectRef in mainlineKey.getObjectRef
                    ())
                {
                    com.discobeard.spriter.dom.TimeLine timeline = timeLines[objectRef.getTimeline()];
                    com.discobeard.spriter.dom.Key timelineKey = timeline.getKey()[objectRef.getKey()
                        ];
                    com.brashmonkey.spriter.objects.SpriterObject @object = objectMerger.merge(objectRef
                        , timelineKey);
                    @object.setName(timeline.getName());
                    if (mainlineKey.getTime() != timelineKey.getTime())
                    {
                        objectsToTween.Add(@object, k);
                    }
                    else
                    {
                        tempObjects.Add(@object);
                    }
                }
                //}
                frame.setObjects(Sharpen.Collections.ToArray(tempObjects, new com.brashmonkey.spriter.objects.SpriterObject
                    [tempObjects.Count]));
                frame.setBones(Sharpen.Collections.ToArray(tempBones, new com.brashmonkey.spriter.objects.SpriterBone
                    [tempBones.Count]));
                spriterAnimation.frames.Add(frame);
            }
            this.tweenBones(spriterAnimation);
            this.tweenObjects(spriterAnimation);
            return spriterAnimation;
        }
Beispiel #10
0
 protected internal override void step(float xOffset, float yOffset)
 {
     //Fetch information
     //SpriterAnimation anim = this.animation;
     System.Collections.Generic.IList<com.brashmonkey.spriter.animation.SpriterKeyFrame
         > frameList = this.animation.frames;
     if (this.transitionFixed && this.transitionTempFixed)
     {
         //anim = this.animation;
         if (this.frameSpeed >= 0)
         {
             firstKeyFrame = frameList[this.currentKey];
             secondKeyFrame = frameList[(this.currentKey + 1) % frameList.Count];
         }
         else
         {
             secondKeyFrame = frameList[this.currentKey];
             firstKeyFrame = 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.currentKey == frameList.Count - 1)
         {
             frameList[0].setTime(this.animation.length);
         }
         else
         {
             frameList[0].setTime(0);
             if (this.frame > secondKeyFrame.getTime() && this.frameSpeed >= 0)
             {
                 this.currentKey = (this.currentKey + 1) % frameList.Count;
                 this.frame = frameList[this.currentKey].getTime();
             }
             else
             {
                 if (this.frame < firstKeyFrame.getTime())
                 {
                     this.currentKey = ((this.currentKey - 1) + frameList.Count) % frameList.Count;
                     this.frame = frameList[this.currentKey].getTime();
                 }
             }
         }
     }
     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;
     if (this.updateBones)
     {
         this.transformBones(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
     }
     if (this.updateObjects)
     {
         this.transformObjects(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
     }
 }
Beispiel #11
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;
            }
        }
Beispiel #12
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="com.discobeard.spriter.dom.SpriterData">com.discobeard.spriter.dom.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(com.discobeard.spriter.dom.SpriterData data, com.discobeard.spriter.dom.Entity
			 entity, com.brashmonkey.spriter.file.FileLoader loader)
            : base(loader, null)
        {
            this.entity = entity;
            this.frame = 0;
            if (!alreadyLoaded(entity))
            {
                this.animations = com.brashmonkey.spriter.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);
        }
Beispiel #13
0
 protected internal override void step(float xOffset, float yOffset)
 {
     //Fetch information
     //SpriterAnimation anim = this.animation;
     System.Collections.Generic.IList <com.brashmonkey.spriter.animation.SpriterKeyFrame
                                       > frameList = this.animation.frames;
     if (this.transitionFixed && this.transitionTempFixed)
     {
         //anim = this.animation;
         if (this.frameSpeed >= 0)
         {
             firstKeyFrame  = frameList[this.currentKey];
             secondKeyFrame = frameList[(this.currentKey + 1) % frameList.Count];
         }
         else
         {
             secondKeyFrame = frameList[this.currentKey];
             firstKeyFrame  = 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.currentKey == frameList.Count - 1)
         {
             frameList[0].setTime(this.animation.length);
         }
         else
         {
             frameList[0].setTime(0);
             if (this.frame > secondKeyFrame.getTime() && this.frameSpeed >= 0)
             {
                 this.currentKey = (this.currentKey + 1) % frameList.Count;
                 this.frame      = frameList[this.currentKey].getTime();
             }
             else
             {
                 if (this.frame < firstKeyFrame.getTime())
                 {
                     this.currentKey = ((this.currentKey - 1) + frameList.Count) % frameList.Count;
                     this.frame      = frameList[this.currentKey].getTime();
                 }
             }
         }
     }
     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;
     if (this.updateBones)
     {
         this.transformBones(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
     }
     if (this.updateObjects)
     {
         this.transformObjects(firstKeyFrame, secondKeyFrame, xOffset, yOffset);
     }
 }
Beispiel #14
0
 //import com.brashmonkey.spriter.converters.SpriterObjectConverter;
 //import com.discobeard.spriter.dom.AnimationObject;
 //final private SpriterObjectConverter objectConverter = new SpriterObjectConverter();
 public virtual com.brashmonkey.spriter.animation.SpriterAnimation buildAnimation(
     com.discobeard.spriter.dom.Animation animation)
 {
     com.discobeard.spriter.dom.MainLine mainline = animation.getMainline();
     System.Collections.Generic.IList <com.discobeard.spriter.dom.TimeLine> timeLines =
         animation.getTimeline();
     System.Collections.Generic.IList <com.discobeard.spriter.dom.Key> keyFrames = mainline
                                                                                   .getKey();
     bonesToTween = new System.Collections.Generic.Dictionary <com.brashmonkey.spriter.objects.SpriterBone
                                                               , int>();
     objectsToTween = new System.Collections.Generic.Dictionary <com.brashmonkey.spriter.objects.SpriterObject
                                                                 , int>();
     com.brashmonkey.spriter.animation.SpriterAnimation spriterAnimation = new com.brashmonkey.spriter.animation.SpriterAnimation
                                                                               (animation.getId(), animation.getName(), animation.getLength());
     for (int k = 0; k < keyFrames.Count; k++)
     {
         com.discobeard.spriter.dom.Key mainlineKey = keyFrames[k];
         System.Collections.Generic.IList <com.brashmonkey.spriter.objects.SpriterObject> tempObjects
             = new System.Collections.Generic.List <com.brashmonkey.spriter.objects.SpriterObject
                                                    >();
         System.Collections.Generic.IList <com.brashmonkey.spriter.objects.SpriterBone> tempBones
             = new System.Collections.Generic.List <com.brashmonkey.spriter.objects.SpriterBone
                                                    >();
         com.brashmonkey.spriter.animation.SpriterKeyFrame frame = new com.brashmonkey.spriter.animation.SpriterKeyFrame
                                                                       ();
         frame.setTime(mainlineKey.getTime());
         frame.setId(mainlineKey.getId());
         foreach (com.discobeard.spriter.dom.BoneRef boneRef in mainlineKey.getBoneRef())
         {
             com.discobeard.spriter.dom.TimeLine         timeline    = timeLines[boneRef.getTimeline()];
             com.discobeard.spriter.dom.Key              timelineKey = timeline.getKey()[boneRef.getKey()];
             com.brashmonkey.spriter.objects.SpriterBone bone        = boneMerger.merge(boneRef, timelineKey
                                                                                        );
             bone.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 bonesToTween.Add(bone, k);
             }
             else
             {
                 tempBones.Add(bone);
             }
         }
         //}
         foreach (com.discobeard.spriter.dom.AnimationObjectRef objectRef in mainlineKey.getObjectRef
                      ())
         {
             com.discobeard.spriter.dom.TimeLine timeline    = timeLines[objectRef.getTimeline()];
             com.discobeard.spriter.dom.Key      timelineKey = timeline.getKey()[objectRef.getKey()
                                                               ];
             com.brashmonkey.spriter.objects.SpriterObject @object = objectMerger.merge(objectRef
                                                                                        , timelineKey);
             @object.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 objectsToTween.Add(@object, k);
             }
             else
             {
                 tempObjects.Add(@object);
             }
         }
         //}
         frame.setObjects(Sharpen.Collections.ToArray(tempObjects, new com.brashmonkey.spriter.objects.SpriterObject
                                                      [tempObjects.Count]));
         frame.setBones(Sharpen.Collections.ToArray(tempBones, new com.brashmonkey.spriter.objects.SpriterBone
                                                    [tempBones.Count]));
         spriterAnimation.frames.Add(frame);
     }
     this.tweenBones(spriterAnimation);
     this.tweenObjects(spriterAnimation);
     return(spriterAnimation);
 }
        /// <summary>Constructs a new SpriterAbstractPlayer object which is able to animate SpriterBone instances and SpriterObject instances.
        /// 	</summary>
        /// <remarks>Constructs a new SpriterAbstractPlayer object which is able to animate SpriterBone instances and SpriterObject instances.
        /// 	</remarks>
        /// <param name="loader">
        /// 
        /// <see cref="com.brashmonkey.spriter.file.FileLoader{I}">com.brashmonkey.spriter.file.FileLoader&lt;I&gt;
        /// 	</see>
        /// which you have to implement on your own.
        /// </param>
        /// <param name="keyframes">
        /// A list of SpriterKeyFrame arrays. See
        /// <see cref="com.brashmonkey.spriter.SpriterKeyFrameProvider.generateKeyFramePool(com.discobeard.spriter.dom.SpriterData, com.discobeard.spriter.dom.Entity)
        /// 	">com.brashmonkey.spriter.SpriterKeyFrameProvider.generateKeyFramePool(com.discobeard.spriter.dom.SpriterData, com.discobeard.spriter.dom.Entity)
        /// 	</see>
        /// to get the list.
        /// Generate these keyframes once to save memory.
        /// </param>
        public SpriterAbstractPlayer(com.brashmonkey.spriter.file.FileLoader loader,
            System.Collections.Generic.IList<com.brashmonkey.spriter.animation.SpriterAnimation
			> animations)
        {
            this.loader = loader;
            this.animations = animations;
            this.rootParent = new com.brashmonkey.spriter.objects.SpriterBone();
            this.tempParent = new com.brashmonkey.spriter.objects.SpriterBone();
            this.rootParent.setName("playerRoot");
            this.tempParent.setName("playerRoot");
            this.lastFrame = new com.brashmonkey.spriter.animation.SpriterKeyFrame();
            this.lastTempFrame = new com.brashmonkey.spriter.animation.SpriterKeyFrame();
            this.interpolator = com.brashmonkey.spriter.interpolation.SpriterLinearInterpolator
                .interpolator;
            this.players = new System.Collections.Generic.LinkedList<com.brashmonkey.spriter.player.SpriterAbstractPlayer>();
            rect = new com.brashmonkey.spriter.SpriterRectangle(0, 0, 0, 0);
        }