Пример #1
0
 private static void loadMainlineKeys(List <XmlNode
                                            > keys, MainLine main)
 {
     for (int i = 0; i < keys.Count; i++)
     {
         XmlNode k   = keys[i];
         Key     key = new Key();
         key.setId(XmlReader.getInt(k, "id"));
         int time = XmlReader.getInt(k, "time", -1);
         if (time == -1)
         {
             key.setTime(0);
         }
         else
         {
             key.setTime(System.Convert.ToInt64(time));
         }
         main.getKey().Add(key);
         loadRefs(XmlReader.getChildrenByName(k, "object_ref"), XmlReader.getChildrenByName(k, "bone_ref"), key);
     }
 }
Пример #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);
        }