嗨,我在这里做一个应用程序使用和引擎,当我单击按钮时,我需要移动两个精灵精灵移动正常,但是我的要求现在两个精灵在单击按钮时两个精灵都在相反的方向上,两个精灵都想要移动,然后当两个精灵都移动时居中屏幕有大约 100 距离我想停止动画。我尝试使用下面的代码,但它计算起始精灵位置,而移动时间它不计算精灵位置你可以帮助我....
final float centerX = (CAMERA_WIDTH - this.mPaddleTextureRegionbtn.getWidth());
final float centerY = (CAMERA_HEIGHT - this.mPaddleTextureRegionbtn.getHeight()) / 2;
paddle = new Sprite(centerX, centerY, this.mPaddleTextureRegionbtn, this.getVertexBufferObjectManager());
final PhysicsHandler physicsHandler = new PhysicsHandler(paddle);
paddle.registerUpdateHandler(physicsHandler);
scene.attachChild(paddle);
final AnimatedSprite banana = new AnimatedSprite(0, centerY, this.mBananaTextureRegion, this.getVertexBufferObjectManager());
banana.animate(100);
scene.attachChild(banana);
final float centerX1 = (CAMERA_WIDTH - this.mPaddleTextureRegion1.getWidth()) / 38;
final float centerY1 = (CAMERA_HEIGHT - this.mPaddleTextureRegion1.getHeight()) /7;
ButtonSprite moveRightButton = new ButtonSprite(centerX1, centerY1, this.mPaddleTextureRegion1, this.getVertexBufferObjectManager(), new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
float pTouchAreaLocalY) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Pong.this, "Haiii-------------", Toast.LENGTH_LONG).show();
MoveXModifier mod = new MoveXModifier(2, banana.getX(), paddle.getX()-100);
banana.registerEntityModifier(mod);
MoveXModifier mod1 = new MoveXModifier(2, paddle.getX(),banana.getX()+100);
paddle.registerEntityModifier(mod1);
}
});
}
});
scene.attachChild(moveRightButton);
scene.registerTouchArea(moveRightButton);
scene.setTouchAreaBindingOnActionDownEnabled(true);