Пример #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
                         ();
            }
        }
Пример #2
0
 protected virtual void drawBones(com.brashmonkey.spriter.player.SpriterAbstractPlayer
                                  player)
 {
     this.setDrawColor(1, 0, 0, 1);
     for (int i = 0; i < player.getBonesToAnimate(); i++)
     {
         com.brashmonkey.spriter.objects.SpriterBone bone = player.getRuntimeBones()[i];
         float xx = bone.getX() + (float)System.Math.Cos(DegreeToRadian(bone.getAngle
                                                                            ())) * 5;
         float yy = bone.getY() + (float)System.Math.Sin(DegreeToRadian(bone.getAngle
                                                                            ())) * 5;
         float x2 = (float)System.Math.Cos(DegreeToRadian(bone.getAngle() + 90)) *
                    (SpriterCalculator.BONE_WIDTH / 2) * bone.getScaleY();
         float y2 = (float)System.Math.Sin(DegreeToRadian(bone.getAngle() + 90)) *
                    (SpriterCalculator.BONE_WIDTH / 2) * bone.getScaleY();
         float targetX = bone.getX() + (float)System.Math.Cos(DegreeToRadian(bone.getAngle
                                                                                 ())) * SpriterCalculator.BONE_LENGTH * bone.getScaleX();
         float targetY = bone.getY() + (float)System.Math.Sin(DegreeToRadian(bone.getAngle
                                                                                 ())) * SpriterCalculator.BONE_LENGTH * bone.getScaleX();
         float upperPointX = xx + x2;
         float upperPointY = yy + y2;
         this.drawLine(bone.getX(), bone.getY(), upperPointX, upperPointY);
         this.drawLine(upperPointX, upperPointY, targetX, targetY);
         float lowerPointX = xx - x2;
         float lowerPointY = yy - y2;
         this.drawLine(bone.getX(), bone.getY(), lowerPointX, lowerPointY);
         this.drawLine(lowerPointX, lowerPointY, targetX, targetY);
         this.drawLine(bone.getX(), bone.getY(), targetX, targetY);
     }
 }