我想在给定的路径上移动一只兔子。然后我在右侧创造了一只兔子,胡萝卜就在左边。我已经给了路径,但兔子移动自动,我使用了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;
}
答案 0 :(得分: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;
}
并将精灵的触摸区域注册到场景。