Esempio n. 1
0
        /// <summary>
        /// Updates the bone and object structure with the given time to the given root bone. </summary>
        /// <param name="time"> The time which has to be between 0 and <seealso cref="#length"/> to work properly. </param>
        /// <param name="root"> The root bone which is not allowed to be null. The whole animation runs relative to the root bone. </param>
        public virtual void Update(int time, Bone root)
        {
            if (!this.prepared)
            {
                throw new SpriterException("This animation is not ready yet to animate itself. Please call prepare()!");
            }
            if (root == null)
            {
                throw new SpriterException("The root can not be null! Set a root bone to apply this animation relative to the root bone.");
            }
            this.CurrentKey = Mainline.GetKeyBeforeTime(time);

            foreach (Timeline.Key timelineKey in this.UnmappedTweenedKeys)
            {
                timelineKey.Active = false;
            }
            foreach (Mainline.Key.BoneRef @ref in CurrentKey.BoneRefs)
            {
                this.Update(@ref, root, time);
            }
            foreach (Mainline.Key.ObjectRef @ref in CurrentKey.ObjectRefs)
            {
                this.Update(@ref, root, time);
            }
        }
Esempio n. 2
0
        /*Timeline getSimilarTimeline(BoneRef ref, Collection<Timeline> coveredTimelines){
         *      if(ref.Parent == null) return null;
         *      for(BoneRef boneRef: this.currentKey.objectRefs){
         *              Timeline t = this.getTimeline(boneRef.Timeline);
         *              if(boneRef.Parent != null && boneRef.Parent.id == ref.Parent.id && !coveredTimelines.contains(t))
         *                      return t;
         *      }
         *      return null;
         * }
         *
         * Timeline getSimilarTimeline(ObjectRef ref, Collection<Timeline> coveredTimelines){
         *      if(ref.Parent == null) return null;
         *      for(ObjectRef objRef: this.currentKey.objectRefs){
         *              Timeline t = this.getTimeline(objRef.Timeline);
         *              if(objRef.Parent != null && objRef.Parent.id == ref.Parent.id && !coveredTimelines.contains(t))
         *                      return t;
         *      }
         *      return null;
         * }*/

        /// <summary>
        /// Prepares this animation to set this animation in any time state.
        /// This method has to be called before <seealso cref="#update(int, Bone)"/>.
        /// </summary>
        public virtual void Prepare()
        {
            if (this.prepared)
            {
                return;
            }
            this.TweenedKeys         = new Timeline.Key[timelines.Length];
            this.UnmappedTweenedKeys = new Timeline.Key[timelines.Length];

            for (int i = 0; i < this.TweenedKeys.Length; i++)
            {
                this.TweenedKeys[i]                = new Timeline.Key(i);
                this.UnmappedTweenedKeys[i]        = new Timeline.Key(i);
                this.TweenedKeys[i].Object         = new SpriterObject(new Point(0, 0));
                this.UnmappedTweenedKeys[i].Object = new SpriterObject(new Point(0, 0));
            }
            if (Mainline.Keys.Length > 0)
            {
                CurrentKey = Mainline.GetKey(0);
            }
            this.prepared = true;
        }