예제 #1
0
        public virtual void resolve(float x, float y, int chainLength, com.brashmonkey.spriter.objects.SpriterAbstractObject
                                    effector)
        {
            float xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * SpriterCalculator.BONE_LENGTH * effector
                       .getScaleX();
            float yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * SpriterCalculator.BONE_LENGTH * effector
                       .getScaleX();

            effector.setAngle(com.brashmonkey.spriter.SpriterCalculator.angleBetween(effector
                                                                                     .getX(), effector.getY(), x, y));
            if (this.player.getFlipX() == -1)
            {
                effector.setAngle(effector.getAngle() + 180f);
            }
            com.brashmonkey.spriter.objects.SpriterBone parent = null;
            if (effector.hasParent())
            {
                parent = player.getRuntimeBones()[effector.getParentId()];
                effector.copyValuesTo(temp);
                com.brashmonkey.spriter.SpriterCalculator.reTranslateRelative(parent, temp);
                if (effector is com.brashmonkey.spriter.objects.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) <= 1)
                {
                    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)));
                this.player.updateRecursively(parent);
                if (parent.hasParent())
                {
                    parent = player.getRuntimeBones()[parent.getParent().getId()];
                }
                else
                {
                    parent = null;
                }
                xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * SpriterCalculator.BONE_LENGTH * effector.getScaleX
                         ();
                yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * SpriterCalculator.BONE_LENGTH * effector.getScaleX
                         ();
            }
        }
 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 tweenBone(SpriterBone currentBone, SpriterBone
                               nextBone, int i, long startTime, long endTime)
        {
            currentBone.copyValuesTo(this.tempBones[i]);
            this.tempBones[i].setTimeline((nextBone != null) ? currentBone.getTimeline() : -1
                                          );
            SpriterAbstractObject parent = (this.tempBones[i]
                                            .hasParent()) ? this.tempBones[this.tempBones[i].getParentId()] : this.tempParent;

            if (nextBone != null)
            {
                if (parent != this.tempParent)
                {
                    if (!currentBone.getParent().equals(nextBone.getParent()))
                    {
                        nextBone = (SpriterBone)this.getTimelineObject(currentBone
                                                                       , this.tempBones2);
                        SpriterCalculator.reTranslateRelative(parent, nextBone);
                        nextBone.setAngle(nextBone.getAngle() * this.flippedX * this.flippedY);
                    }
                }
                else
                {
                    if (nextBone.hasParent())
                    {
                        nextBone = (SpriterBone)this.getTimelineObject(currentBone
                                                                       , this.tempBones2);
                        SpriterCalculator.reTranslateRelative(parent, nextBone);
                        nextBone.setAngle(nextBone.getAngle() * this.flippedX * this.flippedY);
                    }
                }
                if (this.tempBones[i].active)
                {
                    this.interpolateAbstractObject(this.tempBones[i], currentBone, nextBone, startTime
                                                   , endTime);
                }
            }
            this.moddedBones[currentBone.getId()].modSpriterBone(this.tempBones[i]);
            if (this.transitionFixed)
            {
                this.tempBones[i].copyValuesTo(this.lastFrame.getBones()[i]);
            }
            else
            {
                this.tempBones[i].copyValuesTo(this.lastTempFrame.getBones()[i]);
            }
            if (!this.tempBones[i].hasParent() || !this.moddedBones[currentBone.getId()].isActive
                    ())
            {
                this.tempBones[i].setX(this.tempBones[i].getX() + this.pivotX);
                this.tempBones[i].setY(this.tempBones[i].getY() + this.pivotY);
            }
            this.translateRelative(this.tempBones[i], parent);
        }
 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);
     }
 }
 private void translateRoot()
 {
     this.rootParent.copyValuesTo(tempParent);
     this.tempParent.setAngle(this.tempParent.getAngle() * this.flippedX * this.flippedY + this
                              .rootParent.getParent().getAngle());
     this.tempParent.setScaleX(this.tempParent.getScaleX() * this.rootParent.getParent
                                   ().getScaleX());
     this.tempParent.setScaleY(this.tempParent.getScaleY() * this.rootParent.getParent
                                   ().getScaleY());
     SpriterCalculator.translateRelative(this.rootParent.getParent
                                             (), this.tempParent);
 }
        //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);
        }
예제 #7
0
 protected float DegreeToRadian(float angle)
 {
     return(SpriterCalculator.DegreeToRadian(angle));
 }
예제 #8
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
                         ();
            }
        }