2015-07-19 62 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可以簡化,但我將它留給一個奇怪的評論者