Пример #1
0
        public virtual SpriterKeyFrame getNextFrameFor(
			SpriterAbstractObject @object, SpriterKeyFrame
			 currentFrame, int direction)
        {
            SpriterKeyFrame nextFrame = null;
            int cnt = 0;
            bool isBone = @object is SpriterBone;
            for (int j = (currentFrame.getId() + direction + this.keyframes()) % this.keyframes();
                nextFrame == null && cnt < this.keyframes(); j = (j + direction + this.keyframes()) %
                this.keyframes(), cnt++)
            {
                SpriterKeyFrame frame = this.frames[j];
                bool contains = (isBone) ? frame.containsBone((SpriterBone
                    )@object) : frame.containsObject((SpriterObject)
                    @object);
                if (contains)
                {
                    SpriterAbstractObject objectInFrame;
                    if (isBone) objectInFrame = frame.getBoneFor((SpriterBone)@object);
                    else objectInFrame = frame.getObjectFor((SpriterObject)@object);
                    if (@object.equals(objectInFrame))
                    {
                        nextFrame = frame;
                    }
                }
            }
            return nextFrame;
        }
Пример #2
0
 private void modObject(SpriterAbstractObject @object
                        )
 {
     @object.setAngle(@object.getAngle() + this.angle);
     @object.setScaleX(@object.getScaleX() * this.scaleX);
     @object.setScaleY(@object.getScaleY() * this.scaleY);
     @object.setX(@object.getX() + this.x);
     @object.setY(@object.getY() + this.y);
 }
Пример #3
0
 public override void copyValuesTo(SpriterAbstractObject
                                   bone)
 {
     base.copyValuesTo(bone);
     if (!(bone is SpriterBone))
     {
         return;
     }
     ((SpriterBone)bone).childBones   = this.childBones;
     ((SpriterBone)bone).childObjects = this.childObjects;
 }
        /// <param name="rootParent">the rootParent to set</param>
        internal virtual void setRootParent(SpriterAbstractObject
			 rootParent)
        {
            this.rootParent = rootParent;
        }
        protected internal virtual SpriterAbstractObject getTimelineObject(SpriterAbstractObject @object, 
			SpriterAbstractObject[] objects)
        {
            for (int i = 0; i < objects.Length; i++)
            {
                if (objects[i].getTimeline().Equals(@object.getTimeline()))
                {
                    return objects[i];
                }
            }
            return null;
        }
        /// <param name="rootParent">the rootParent to set</param>
        internal virtual void changeRootParent(SpriterAbstractObject
			 rootParent)
        {
            this.rootParent.setParent(rootParent);
        }
 public virtual void updateAbstractObject(SpriterAbstractObject @object)
 {
     if (@object.hasParent())
     {
         SpriterAbstractObject obj = (@object is SpriterBone
             ) ? (SpriterAbstractObject)this.lastFrame.getBones()[@object.getId()] : this.lastFrame.getObjects()[@object
             .getId()];
         SpriterCalculator.translateRelative(this.tempBones[@object
             .getParentId()], obj.getX(), obj.getY(), @object);
     }
 }
Пример #8
0
        public override void copyValuesTo(SpriterAbstractObject
			 bone)
        {
            base.copyValuesTo(bone);
            if (!(bone is SpriterBone))
            {
                return;
            }
            ((SpriterBone)bone).childBones = this.childBones;
            ((SpriterBone)bone).childObjects = this.childObjects;
        }
        private void updateTempObject(SpriterAbstractObject
			 source, SpriterAbstractObject[] target)
        {
            bool found = false;
            for (int j = 0; j < target.Length && !found; j++)
            {
                if (source.getId() == target[j].getId())
                {
                    source.copyValuesTo(target[j]);
                    found = true;
                }
            }
        }
 /// <summary>Constructs a new SpriterAbstractPlayer object which is able to animate SpriterBone instances and SpriterObject instances.
 /// 	</summary>
 /// <remarks>Constructs a new SpriterAbstractPlayer object which is able to animate SpriterBone instances and SpriterObject instances.
 /// 	</remarks>
 /// <param name="loader">
 /// 
 /// <see cref="FileLoader{I}">FileLoader&lt;I&gt;
 /// 	</see>
 /// which you have to implement on your own.
 /// </param>
 /// <param name="keyframes">
 /// A list of SpriterKeyFrame arrays. See
 /// <see cref="SpriterKeyFrameProvider.generateKeyFramePool(com.discobeard.spriter.dom.SpriterData, com.discobeard.spriter.dom.Entity)
 /// 	">SpriterKeyFrameProvider.generateKeyFramePool(com.discobeard.spriter.dom.SpriterData, com.discobeard.spriter.dom.Entity)
 /// 	</see>
 /// to get the list.
 /// Generate these keyframes once to save memory.
 /// </param>
 public SpriterAbstractPlayer(FileLoader loader, IList<SpriterAnimation> animations)
 {
     this.loader = loader;
     this.animations = animations;
     this.rootParent = new SpriterBone();
     this.tempParent = new SpriterBone();
     this.rootParent.setName("playerRoot");
     this.tempParent.setName("playerRoot");
     this.lastFrame = new SpriterKeyFrame();
     this.lastTempFrame = new SpriterKeyFrame();
     this.interpolator = SpriterLinearInterpolator
         .interpolator;
     this.players = new List<SpriterAbstractPlayer>();
     rect = new SpriterRectangle(0, 0, 0, 0);
 }
Пример #11
0
 /// <summary>Resolves the inverse kinematics constraint with a specific algtorithm</summary>
 /// <param name="x">the target x value</param>
 /// <param name="y">the target y value</param>
 /// <param name="chainLength">number of parents which are affected</param>
 /// <param name="effector">the actual effector where the resolved information has to be stored in.
 /// 	</param>
 protected abstract void resolve(float x, float y, int chainLength, SpriterAbstractObject effector, SpriterAbstractPlayer player);
Пример #12
0
        protected internal virtual void updateRecursively(SpriterAbstractPlayer
			 player, SpriterAbstractObject @object)
        {
            this.updateObject(player, @object);
            if (@object is SpriterBone)
            {
                foreach (SpriterBone child in ((SpriterBone
                    )@object).getChildBones())
                {
                    this.updateRecursively(player, player.getRuntimeBones()[child.getId()]);
                }
                foreach (SpriterObject child_1 in ((SpriterBone
                    )@object).getChildObjects())
                {
                    this.updateRecursively(player, player.getRuntimeObjects()[child_1.getId()]);
                }
            }
        }
Пример #13
0
        protected internal virtual void updateObject(SpriterAbstractPlayer
			 player, SpriterAbstractObject @object)
        {
            player.updateAbstractObject(@object);
        }
Пример #14
0
        /// <summary>Adds the given object to the internal SpriterIKObject - SpriterBone map, which works like a HashMap.
        /// 	</summary>
        /// <remarks>
        /// Adds the given object to the internal SpriterIKObject - SpriterBone map, which works like a HashMap.
        /// This means, the values of the given object affect the mapped bone.
        /// </remarks>
        /// <param name="object"></param>
        /// <param name="bone"></param>
        public virtual void mapIKObject(SpriterIKObject @object
			, SpriterAbstractObject abstractObject)
        {
            this.ikMap.Add(@object, abstractObject);
        }
        private void translateRelative(SpriterAbstractObject
			 @object, SpriterAbstractObject parent)
        {
            @object.setAngle(@object.getAngle() * this.flippedX * this.flippedY + parent.getAngle()
                );
            @object.setScaleX(@object.getScaleX() * parent.getScaleX());
            @object.setScaleY(@object.getScaleY() * parent.getScaleY());
            SpriterCalculator.translateRelative(parent, @object);
        }
 private void interpolateAbstractObject(SpriterAbstractObject
      target, SpriterAbstractObject obj1, SpriterAbstractObject
      obj2, float startTime, float endTime, float frame)
 {
     if (obj2 == null)
     {
         return;
     }
     target.setX(this.interpolate(obj1.getX(), obj2.getX(), startTime, endTime, frame)
         );
     target.setY(this.interpolate(obj1.getY(), obj2.getY(), startTime, endTime, frame)
         );
     target.setScaleX(this.interpolate(obj1.getScaleX(), obj2.getScaleX(), startTime,
         endTime, frame));
     target.setScaleY(this.interpolate(obj1.getScaleY(), obj2.getScaleY(), startTime,
         endTime, frame));
     target.setAngle(this.interpolateAngle(obj1.getAngle(), obj2.getAngle(), startTime
         , endTime, frame));
 }
        private void updateTransformedTempObject(SpriterAbstractObject
			 source, SpriterAbstractObject target)
        {
            source.copyValuesTo(target);
            if (!target.hasParent())
            {
                target.setX(target.getX() + this.pivotX);
                target.setY(target.getY() + this.pivotY);
            }
            this.translateRelative(target, (target.hasParent()) ? this.tempBones2[target.getParentId
                ()] : this.tempParent);
        }
Пример #18
0
 protected override void resolve(float x, float y, int chainLength, SpriterAbstractObject effector, SpriterAbstractPlayer player)
 {
     base.updateRecursively(player, effector);
     float xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector
         .getAngle())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector
         .getScaleX();
     float yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector
         .getAngle())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector
         .getScaleX();
     effector.setAngle(Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(effector
         .getX(), effector.getY(), x, y));
     if (player.getFlipX() == -1)
     {
         effector.setAngle(effector.getAngle() + 180f);
     }
     SpriterBone parent = null;
     if (effector.hasParent())
     {
         parent = player.getRuntimeBones()[effector.getParentId()];
     }
     //effector.copyValuesTo(temp);
     //SpriterCalculator.reTranslateRelative(parent, temp);
     //if(effector instanceof SpriterBone)	temp.copyValuesTo(player.lastFrame.getBones()[effector.getId()]);
     //else temp.copyValuesTo(player.lastFrame.getObjects()[effector.getId()]);
     for (int i = 0; i < chainLength && parent != null; i++)
     {
         if (Com.Brashmonkey.Spriter.SpriterCalculator.distanceBetween(xx, yy, x, y) <= this
             .tolerance)
         {
             SpriterBone p = null;
             if (parent.hasParent())
             {
                 p = player.getRuntimeBones()[parent.getParentId()];
             }
             int j = 0;
             while (p != null && j < chainLength)
             {
                 base.updateRecursively(player, p);
                 if (p.hasParent())
                 {
                     p = player.getRuntimeBones()[p.getParentId()];
                 }
                 else
                 {
                     p = null;
                 }
                 j++;
             }
             return;
         }
         parent.setAngle(parent.getAngle() + Com.Brashmonkey.Spriter.SpriterCalculator.angleDifference
             (Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(parent.getX(), parent.getY
             (), x, y), Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(parent.getX(),
             parent.getY(), xx, yy)));
         base.updateRecursively(player, parent);
         if (parent.hasParent())
         {
             parent = player.getRuntimeBones()[parent.getParent().getId()];
         }
         else
         {
             parent = null;
         }
         xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector.getAngle
             ())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector.getScaleX
             ();
         yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector.getAngle
             ())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector.getScaleX
             ();
     }
 }
        private void updateTransformedTempObjects(SpriterAbstractObject
			[] source, SpriterAbstractObject[] target)
        {
            for (int i = 0; i < source.Length; i++)
            {
                this.updateTransformedTempObject(source[i], target[i]);
            }
        }
Пример #20
0
        private void modObject(SpriterAbstractObject @object
			)
        {
            @object.setAngle(@object.getAngle() + this.angle);
            @object.setScaleX(@object.getScaleX() * this.scaleX);
            @object.setScaleY(@object.getScaleY() * this.scaleY);
            @object.setX(@object.getX() + this.x);
            @object.setY(@object.getY() + this.y);
        }
        /// <summary>Attaches a given player to this.</summary>
        /// <remarks>Attaches a given player to this.</remarks>
        /// <param name="player">indicates the player which has to be attached.</param>
        /// <param name="root">
        /// indicates the object the attached player has to follow.
        /// Set to
        /// <see cref="getRootParent()">getRootParent()</see>
        /// to attach the player to the same position as this player.
        /// </param>
        public virtual void attachPlayer(SpriterAbstractPlayer
			 player, SpriterAbstractObject root)
        {
            this.players.Add(player);
            player.changeRootParent(root);
        }