嗨我正在做一个应用程序使用和引擎在这里当我点击按钮那个时候我需要移动两个精灵精灵正在移动很好,但我的要求现在两个精灵是相反的方向当点击按钮两个精灵想要移动然后中心屏幕当两个精灵都有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);
答案 0 :(得分:0)
试试这个,它可能会帮助你。
MoveXModifier mod = new MoveXModifier(2,banana.getX(),paddle.getX() - 100,new IEntityModifierListener(){
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem)
{
}
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
banana.stopAnimation();
}
});
banana.registerEntityModifier(mod);
你可以为下一步做同样的事。
希望这是你的问题的答案,我能理解。