2015-07-19 56 views
0

我试图让枪的缺点,为此枪应该旋转一点点,然后回去,然后它应该前面一点点(模拟如果射手重新定位)。在Andengine中旋转时MoveModifier

使用MoveByModier执行此操作需要在每个manageUpdate和某个三角函数中更改它。如果我不这样做这样我可以有两条路线(一个修改的拉,另一个重新定位),但其仍难以

This is a 2 points animation, the rectangle displaces to one point,and then to another

这样做,是否有MoveModifier其独立地位和回转?

+0

我明白,要动画枪运动,而射手依然继续,所以枪应移至关于射手位置不是现场? –

+0

射手不移动,我想动画枪,这样,它在角度移动意味着'移动(cos(角度))*值,(罪(角度)*值))'在场景条款。如果它有帮助,我会发布图像 –

+0

Post image please –

回答

0

过了一段时间我想出了如何制作2点动画。

public void drawback (Sprite sprite, float DeltaAngle, float drawback){ 
    Vector2 center= new Vector2(sprite.getRotationCenterX(),sprite.getRotationCenterY()); 
    Vector2 radiusPoint = new Vector2(sprite.getWidth(),sprite.getHeight()); 
    float radius = radiusPoint.dst(center)/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT; 

    Vector2 currentPosition= new Vector2(sprite.getX(),sprite.getY()); 

    Vector2 pointA = new Vector2(
      (float)Math.cos(Math.toRadians(DeltaAngle/2+180))*drawback + Float.valueOf (sprite.getX()), 
      (float)Math.sin(Math.toRadians(DeltaAngle/2+180))*drawback + Float.valueOf (sprite.getY()) ); 

    Vector2 pointB = new Vector2(
      (float) Math.cos (Math.toRadians((DeltaAngle)))*radius + Float.valueOf (sprite.getX()), 
      (float) Math.sin (Math.toRadians((DeltaAngle)))*radius + Float.valueOf (sprite.getY())); 



    sprite.registerEntityModifier(new ParallelEntityModifier(
      new RotationByModifier(2,15), 
      new SequenceEntityModifier(
        new PathModifier(.5f,new PathModifier.Path(
          new float[]{currentPosition.x,pointA.x}, 
          new float[]{currentPosition.y,pointA.y}))), 
        new PathModifier(1.5f,new PathModifier.Path(
          new float[]{pointA.x,pointB.x}, 
          new float[]{pointA.y,pointB.y})) 
    ));} 

我相信在trygonometry可以简化,但我将它留给一个奇怪的评论者