Beispiel #1
0
        public virtual void addChildObject(SpriterObject 
			@object)
        {
            @object.setParent(this);
            childObjects.Add(@object);
        }
 private void interpolateSpriterObject(SpriterObject
      target, SpriterObject obj1, SpriterObject
      obj2, float startTime, float endTime, float frame)
 {
     if (obj2 == null)
     {
         return;
     }
     this.interpolateAbstractObject(target, obj1, obj2, startTime, endTime, frame);
     target.setPivotX(this.interpolate(obj1.getPivotX(), obj2.getPivotX(), startTime,
         endTime, frame));
     target.setPivotY(this.interpolate(obj1.getPivotY(), obj2.getPivotY(), startTime,
         endTime, frame));
     target.setAlpha(this.interpolateAngle(obj1.getAlpha(), obj2.getAlpha(), startTime
         , endTime, frame));
 }
 //import Com.Brashmonkey.Spriter.converters.SpriterObjectConverter;
 //import AnimationObject;
 //final private SpriterObjectConverter objectConverter = new SpriterObjectConverter();
 public virtual SpriterAnimation buildAnimation(
     Animation animation)
 {
     MainLine mainline = animation.getMainline();
     IList<TimeLine> timeLines =
         animation.getTimeline();
     IList<Key> keyFrames = mainline
         .getKey();
     bonesToTween = new Dictionary<SpriterBone
         , int>();
     objectsToTween = new Dictionary<SpriterObject
         , int>();
     SpriterAnimation spriterAnimation = new SpriterAnimation(animation.getId(), animation.getName(), animation.getLength());
     for (int k = 0; k < keyFrames.Count; k++)
     {
         Key mainlineKey = keyFrames[k];
         IList<SpriterObject> tempObjects
              = new List<SpriterObject
             >();
         IList<SpriterBone> tempBones
              = new List<SpriterBone
             >();
         SpriterKeyFrame frame = new SpriterKeyFrame
             ();
         frame.setTime(mainlineKey.getTime());
         frame.setId(mainlineKey.getId());
         foreach (BoneRef boneRef in mainlineKey.getBoneRef())
         {
             TimeLine timeline = timeLines[boneRef.getTimeline()];
             Key timelineKey = timeline.getKey()[boneRef.getKey()];
             SpriterBone bone = boneMerger.merge(boneRef, timelineKey
                 );
             bone.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 bonesToTween.Add(bone, k);
             }
             else
             {
                 tempBones.Add(bone);
             }
         }
         //}
         foreach (AnimationObjectRef objectRef in mainlineKey.getObjectRef
             ())
         {
             TimeLine timeline = timeLines[objectRef.getTimeline()];
             Key timelineKey = timeline.getKey()[objectRef.getKey()
                 ];
             SpriterObject @object = objectMerger.merge(objectRef
                 , timelineKey);
             @object.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 objectsToTween.Add(@object, k);
             }
             else
             {
                 tempObjects.Add(@object);
             }
         }
         //}
         SpriterObject[] objArray = new SpriterObject[tempObjects.Count];
         tempObjects.CopyTo(objArray,0);
         frame.setObjects(objArray);
         SpriterBone[] boneArray = new SpriterBone[tempBones.Count];
         tempBones.CopyTo(boneArray, 0);
         frame.setBones(boneArray);
         spriterAnimation.frames.Add(frame);
     }
     this.tweenBones(spriterAnimation);
     this.tweenObjects(spriterAnimation);
     return spriterAnimation;
 }
        //else this.tweenObject(this.animations.get(0).frames.get(0).getObjectFor(this.nonTransformedTempObjects[i]), nextFrame.getObjectFor(this.nonTransformedTempObjects[i]), i, currentFrame.getTime(), nextFrame.getTime());
        protected internal virtual void setInstructionRef(DrawInstruction
			 dI, SpriterObject obj1, SpriterObject
			 obj2)
        {
            dI.@ref = obj1.getRef();
            dI.loader = obj1.getLoader();
            dI.obj = obj1;
        }
 public virtual void tweenObjects(SpriterAnimation  animation)
 {
     foreach (SpriterObject key in objectsToTween.Keys)
     {
         SpriterObject toTween = key;
         SpriterKeyFrame frame = animation.frames[objectsToTween[key]];
         long time = frame.getTime();
         SpriterKeyFrame currentFrame = animation.getPreviousFrameForObject
             (toTween, time);
         SpriterKeyFrame nextFrame = animation.getNextFrameFor
             (toTween, currentFrame, 1);
         if (nextFrame != currentFrame)
         {
             SpriterObject object1 = currentFrame.getObjectFor
                 (toTween);
             SpriterObject object2 = nextFrame.getObjectFor(toTween
                 );
             this.interpolateSpriterObject(toTween, object1, object2, currentFrame.getTime(),
                 nextFrame.getTime(), time);
         }
         SpriterObject[] objects = new 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);
     }
 }
 /// <summary>Returns whether this frame has information about the given object.</summary>
 /// <remarks>Returns whether this frame has information about the given object.</remarks>
 /// <param name="object"></param>
 /// <returns>True if this frame contains the object, false otherwise.</returns>
 public virtual bool containsObject(SpriterObject @object)
 {
     return this.getObjectFor(@object) != null;
 }
 /// <summary>Generates data which is necessary to animate all animations as intended.
 /// 	</summary>
 /// <remarks>
 /// Generates data which is necessary to animate all animations as intended.
 /// This method has to called inside the specific constructor.
 /// </remarks>
 protected internal void generateData()
 {
     int maxObjects = 0;
     int maxBones = 0;
     int maxBonesFrameIndex = 0;
     int maxObjectsFrameIndex = 0;
     int maxBonesAnimationIndex = 0;
     int maxObjectsAnimationIndex = 0;
     foreach (SpriterAnimation animation in this.animations)
     {
         foreach (SpriterKeyFrame frame in animation.frames)
         {
             maxBones = System.Math.Max(frame.getBones().Length, maxBones);
             if (maxBones == frame.getBones().Length)
             {
                 maxBonesFrameIndex = frame.getId();
                 maxBonesAnimationIndex = animation.id;
             }
             maxObjects = System.Math.Max(frame.getObjects().Length, maxObjects);
             if (maxObjects == frame.getObjects().Length)
             {
                 maxObjectsFrameIndex = frame.getId();
                 maxObjectsAnimationIndex = animation.id;
             }
             foreach (SpriterObject o in frame.getObjects())
             {
                 o.setLoader(this.loader);
                 o.setRef(this.loader.findReference(o.getRef()));
             }
         }
     }
     this.instructions = new DrawInstruction[maxObjects];
     this.moddedObjects = new SpriterModObject[this.instructions
         .Length];
     this.tempObjects = new SpriterObject[this.instructions
         .Length];
     this.tempObjects2 = new SpriterObject[this.instructions
         .Length];
     this.nonTransformedTempObjects = new SpriterObject
         [this.instructions.Length];
     for (int i = 0; i < this.instructions.Length; i++)
     {
         this.instructions[i] = new DrawInstruction(null, 0,
             0, 0, 0, 0, 0, 0, 0);
         this.tempObjects[i] = new SpriterObject();
         this.tempObjects2[i] = new SpriterObject();
         this.nonTransformedTempObjects[i] = new SpriterObject
             ();
         this.nonTransformedTempObjects[i].setId(i);
         this.moddedObjects[i] = new SpriterModObject();
         this.moddedObjects[i].setId(i);
     }
     this.tempBones = new SpriterBone[maxBones];
     this.tempBones2 = new SpriterBone[tempBones.Length
         ];
     this.nonTransformedTempBones = new SpriterBone[tempBones
         .Length];
     this.moddedBones = new SpriterModObject[this.tempBones
         .Length];
     for (int i_1 = 0; i_1 < this.tempBones.Length; i_1++)
     {
         this.tempBones[i_1] = new SpriterBone();
         this.tempBones2[i_1] = new SpriterBone();
         this.nonTransformedTempBones[i_1] = new SpriterBone
             ();
         this.nonTransformedTempBones[i_1].setId(i_1);
         this.moddedBones[i_1] = new SpriterModObject();
         this.moddedBones[i_1].setId(i_1);
     }
     SpriterBone[] tmpBones1 = new SpriterBone
         [this.tempBones.Length];
     SpriterBone[] tmpBones2 = new SpriterBone
         [this.tempBones.Length];
     SpriterObject[] tmpObjs1 = new SpriterObject
         [this.instructions.Length];
     SpriterObject[] tmpObjs2 = new SpriterObject
         [this.instructions.Length];
     for (int i_2 = 0; i_2 < tmpObjs1.Length; i_2++)
     {
         tmpObjs1[i_2] = new SpriterObject();
         tmpObjs2[i_2] = new SpriterObject();
     }
     for (int i_3 = 0; i_3 < tmpBones1.Length; i_3++)
     {
         tmpBones1[i_3] = new SpriterBone();
         tmpBones2[i_3] = new SpriterBone();
     }
     this.lastFrame.setBones(tmpBones1);
     this.lastFrame.setObjects(tmpObjs1);
     this.lastTempFrame.setBones(tmpBones2);
     this.lastTempFrame.setObjects(tmpObjs2);
     foreach (SpriterObject @object in this.animations
         [maxObjectsAnimationIndex].frames[maxObjectsFrameIndex].getObjects())
     {
         for (int i_4 = 0; i_4 < this.nonTransformedTempObjects.Length; i_4++)
         {
             if (this.nonTransformedTempObjects[i_4].getId() == @object.getId())
             {
                 @object.copyValuesTo(this.nonTransformedTempObjects[i_4]);
             }
         }
     }
     foreach (SpriterBone bone in this.animations[maxBonesAnimationIndex
         ].frames[maxBonesFrameIndex].getBones())
     {
         for (int i_4 = 0; i_4 < this.nonTransformedTempBones.Length; i_4++)
         {
             if (this.nonTransformedTempBones[i_4].getId() == bone.getId())
             {
                 bone.copyValuesTo(this.nonTransformedTempBones[i_4]);
             }
         }
     }
     this.generated = true;
 }
        //else this.tweenBone(this.nonTransformedTempBones[i], this.animations.get(0).frames.get(0).getBoneFor(this.nonTransformedTempBones[i]), i, currentFrame.getTime(), nextFrame.getTime());
        private void tweenObject(SpriterObject currentObject
			, SpriterObject nextObject, int i, long startTime
			, long endTime)
        {
            DrawInstruction dI = this.instructions[i];
            currentObject.copyValuesTo(this.tempObjects[i]);
            SpriterAbstractObject parent = null;
            if (!currentObject.isTransientObject())
            {
                this.tempObjects[i].setTimeline((nextObject != null) ? currentObject.getTimeline(
                    ) : -1);
                parent = (currentObject.hasParent()) ? this.tempBones[currentObject.getParentId()
                    ] : this.tempParent;
                if (nextObject != null)
                {
                    if (parent != this.tempParent)
                    {
                        if (!currentObject.getParent().equals(nextObject.getParent()))
                        {
                            nextObject = (SpriterObject)this.getTimelineObject
                                (currentObject, this.tempObjects2);
                            SpriterCalculator.reTranslateRelative(parent, nextObject);
                            nextObject.setAngle(nextObject.getAngle() * this.flippedX * this.flippedY);
                        }
                    }
                    else
                    {
                        if (nextObject.hasParent())
                        {
                            nextObject = (SpriterObject)this.getTimelineObject
                                (currentObject, this.tempObjects2);
                            SpriterCalculator.reTranslateRelative(parent, nextObject);
                            nextObject.setAngle(nextObject.getAngle() * this.flippedX * this.flippedY);
                        }
                    }
                    if (this.tempObjects[i].active)
                    {
                        this.interpolateSpriterObject(this.tempObjects[i], currentObject, nextObject, startTime
                            , endTime);
                    }
                }
                this.moddedObjects[currentObject.getId()].modSpriterObject(this.tempObjects[i]);
                if (this.transitionFixed)
                {
                    this.tempObjects[i].copyValuesTo(this.lastFrame.getObjects()[i]);
                }
                else
                {
                    this.tempObjects[i].copyValuesTo(this.lastTempFrame.getObjects()[i]);
                }
            }
            else
            {
                parent = this.tempParent;
            }
            if (!this.tempObjects[i].hasParent())
            {
                this.tempObjects[i].setX(this.tempObjects[i].getX() + this.pivotX);
                this.tempObjects[i].setY(this.tempObjects[i].getY() + this.pivotY);
            }
            this.translateRelative(this.tempObjects[i], parent);
            if (this.moddedObjects[currentObject.getId()].getRef() != null)
            {
                this.tempObjects[i].setRef(this.moddedObjects[currentObject.getId()].getRef());
            }
            if (this.moddedObjects[currentObject.getId()].getLoader() != null)
            {
                this.tempObjects[i].setLoader(this.moddedObjects[currentObject.getId()].getLoader
                    ());
            }
            this.tempObjects[i].copyValuesTo(dI);
            this.setInstructionRef(dI, this.tempObjects[i], nextObject);
        }
 /// <summary>Searches for the right mod object for the given object.</summary>
 /// <remarks>Searches for the right mod object for the given object.</remarks>
 /// <param name="object">object to search at.</param>
 /// <returns>right mod object you want access to. Null if not found.</returns>
 public virtual SpriterModObject getModObjectForObject(SpriterObject @object)
 {
     try
     {
         return this.moddedObjects[this.getModObjectIndexForObject(@object)];
     }
     catch (System.IndexOutOfRangeException)
     {
         return null;
     }
 }
        /// <summary>Generates all needed keyframes from the given spriter data.</summary>
        /// <remarks>Generates all needed keyframes from the given spriter data. This method sorts all objects by its z_index value to draw them in a proper way.
        /// 	</remarks>
        /// <param name="spriterData">SpriterData to generate from.</param>
        /// <returns>generated keyframe list.</returns>
        public static IList<SpriterAnimation> generateKeyFramePool(com.discobeard.spriter.dom.SpriterData data, com.discobeard.spriter.dom.Entity
			 entity)
        {
            IList<SpriterAnimation
                > spriterAnimations = new List<SpriterAnimation
                >();
            IList<com.discobeard.spriter.dom.Animation> animations
                 = entity.getAnimation();
            Com.Brashmonkey.Spriter.mergers.SpriterAnimationBuilder frameBuilder = new Com.Brashmonkey.Spriter.mergers.SpriterAnimationBuilder
                ();
            foreach (com.discobeard.spriter.dom.Animation anim in animations)
            {
                SpriterAnimation spriterAnimation = frameBuilder
                    .buildAnimation(anim);
                bool found = false;
                foreach (SpriterKeyFrame key in spriterAnimation
                    .frames)
                {
                    if (!found)
                    {
                        found = key.getTime() == anim.getLength();
                    }
                    sort(key.getObjects());
                    foreach (SpriterBone bone in key.getBones())
                    {
                        foreach (SpriterBone bone2 in key.getBones())
                        {
                            if (bone2.hasParent())
                            {
                                if (!bone2.equals(bone) && bone2.getParentId() == bone.getId())
                                {
                                    bone.addChildBone(bone2);
                                }
                            }
                        }
                        foreach (SpriterObject @object in key.getObjects(
                            ))
                        {
                            Com.Brashmonkey.Spriter.file.Reference @ref = @object.getRef();
                            com.discobeard.spriter.dom.File f = data.getFolder()[@ref.folder].getFile()[@ref.
                                file];
                            @ref.dimensions = new Com.Brashmonkey.Spriter.SpriterRectangle(0, f.getHeight(),
                                f.getWidth(), 0f);
                            if (bone.getId() == @object.getParentId())
                            {
                                bone.addChildObject(@object);
                            }
                        }
                    }
                }
                if (!found)
                {
                    SpriterKeyFrame firstFrame = spriterAnimation.frames
                        [0];
                    SpriterKeyFrame lastFrame = new SpriterKeyFrame
                        ();
                    lastFrame.setId(spriterAnimation.keyframes());
                    lastFrame.setBones(new SpriterBone[firstFrame.getBones
                        ().Length]);
                    lastFrame.setObjects(new SpriterObject[firstFrame
                        .getObjects().Length]);
                    for (int j = 0; j < lastFrame.getBones().Length; j++)
                    {
                        SpriterBone bone = new SpriterBone
                            ();
                        firstFrame.getBones()[j].copyValuesTo(bone);
                        lastFrame.getBones()[j] = bone;
                    }
                    for (int j_1 = 0; j_1 < lastFrame.getObjects().Length; j_1++)
                    {
                        SpriterObject @object = new SpriterObject
                            ();
                        firstFrame.getObjects()[j_1].copyValuesTo(@object);
                        lastFrame.getObjects()[j_1] = @object;
                    }
                    lastFrame.setTime(anim.getLength());
                    spriterAnimation.frames.Add(lastFrame);
                }
                spriterAnimations.Add(spriterAnimation);
            }
            return spriterAnimations;
        }
 /// <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 SpriterKeyFrame getPreviousFrameForObject(SpriterObject @object, long time)
 {
     SpriterKeyFrame frame = null;
     foreach (SpriterKeyFrame key in this.frames)
     {
         if (!key.containsObject(@object))
         {
             continue;
         }
         if (key.getTime() <= time)
         {
             frame = key;
         }
         else
         {
             break;
         }
     }
     return frame;
 }
        public static void sort(SpriterObject[] objects)
        {
            bool PaarSortiert;
            do
            {
                PaarSortiert = true;
                for (int i = 0; i < objects.Length - 1; i++)
                {
                    if (objects[i].getZIndex() > objects[i + 1].getZIndex())
                    {
                        SpriterObject temp = objects[i];
                        objects[i] = objects[i + 1];
                        objects[i + 1] = temp;
                        PaarSortiert = false;
                    }
                }

            } while (!PaarSortiert);
        }
Beispiel #13
0
 public virtual void addChildObject(SpriterObject
                                    @object)
 {
     @object.setParent(this);
     childObjects.Add(@object);
 }
        public virtual SpriterObject getObjectFor(SpriterObject
			 @object)
        {
            foreach (SpriterObject obj in this.objects)
            {
                if (obj.equals(@object))
                {
                    return obj;
                }
            }
            return null;
        }
Beispiel #15
0
 /// <summary>Manipulates the given object.</summary>
 /// <remarks>Manipulates the given object.</remarks>
 /// <param name="object"></param>
 public virtual void modSpriterObject(SpriterObject
                                      @object)
 {
     this.modObject(@object);
     @object.setAlpha(@object.getAlpha() * this.alpha);
 }
        /// <summary>Searches for the right index for a given object.</summary>
        /// <remarks>Searches for the right index for a given object.</remarks>
        /// <param name="object">object to search at.</param>
        /// <returns>right index for the mod object you want access to. -1 if not found.</returns>
        public virtual int getModObjectIndexForObject(SpriterObject
			 @object)
        {
            for (int i = 0; i < this.tempObjects.Length; i++)
            {
                if (this.tempObjects[i].equals(@object))
                {
                    return i;
                }
            }
            return -1;
        }
        /// <summary>Manipulates the given object.</summary>
        /// <remarks>Manipulates the given object.</remarks>
        /// <param name="object"></param>
        public virtual void modSpriterObject(SpriterObject
			 @object)
        {
            this.modObject(@object);
            @object.setAlpha(@object.getAlpha() * this.alpha);
        }
        /// <param name="objects">to set to this keyframe.</param>
        public virtual void setObjects(SpriterObject[] objects
			)
        {
            this.objects = objects;
        }