//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;
        }
 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);
     }
 }
 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);
     }
 }
Exemple #4
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);
 }