예제 #1
0
 public virtual void tweenBones(SpriterAnimation animation)
 {
     foreach (SpriterBone key in bonesToTween.Keys)
     {
         SpriterBone     toTween      = key;
         SpriterKeyFrame frame        = animation.frames[bonesToTween[key]];
         long            time         = frame.getTime();
         SpriterKeyFrame currentFrame = animation.getPreviousFrameForBone
                                            (toTween, time);
         SpriterKeyFrame nextFrame = animation.getNextFrameFor
                                         (toTween, currentFrame, 1);
         if (nextFrame != currentFrame)
         {
             SpriterBone bone1 = currentFrame.getBoneFor(toTween
                                                         );
             SpriterBone bone2 = nextFrame.getBoneFor(toTween);
             this.interpolateAbstractObject(toTween, bone1, bone2, currentFrame.getTime(), nextFrame
                                            .getTime(), time);
         }
         SpriterBone[] bones = new 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);
     }
 }
예제 #2
0
        //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);
        }