1

我想在给定的路径上移动一只兔子。然后我在右侧创建了一只兔子,胡萝卜在左右。我已经给出了路径,但是那只兔子自动移动,我使用了 pathmodifer。

final AnimatedSprite stayrabit = new AnimatedSprite(CAMERA_WIDTH - 58, 90,32,32, this.mrabitTextureRegion, this.getVertexBufferObjectManager()) { 
    final Path path = new Path(10).to(CAMERA_WIDTH - 58, 90).to(10, 90);
}

@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
    //this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
    PathModifier pathModifier = new PathModifier(20, path);

    this.registerEntityModifier(pathModifier);

    return true;
} 
4

1 回答 1

0

像这样在 onAreaTouched 方法上使用此代码 - @Override

public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
   if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP)
   {
      MoveXModifier mod = new MoveXModifier(pDuration, your mouse x position, your carrot x position );
      this.registerEntityModifier(mod);
      return true;
   } 

并将精灵的触摸区域注册到场景。

于 2013-11-19T07:19:07.610 回答