我使用andengine for android,我有多个球在它们和屏幕的限制之间反弹。问题是我在碰撞时所做的是反转 X 和 Y 方向,因此弹跳效果不真实,你怎么办?
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
if(this.mX < 0) {
this.mPhysicsHandler.setVelocityX(DEMO_VELOCITY);
} else if(this.mX + this.getWidth() > CAMERA_WIDTH) {
this.mPhysicsHandler.setVelocityX(-DEMO_VELOCITY);
}
if(this.mY < 0) {
this.mPhysicsHandler.setVelocityY(DEMO_VELOCITY);
} else if(this.mY + this.getHeight() > CAMERA_HEIGHT) {
this.mPhysicsHandler.setVelocityY(-DEMO_VELOCITY);
}
for (int i = 0; i < Bolas.size(); i++) {
if (this.collidesWith(Bolas.get(i)) && Bolas.get(i).equals(this) == false) {
// ????????????????????????????????
this.mPhysicsHandler.setVelocityY((-1) * this.mPhysicsHandler.getVelocityY());
this.mPhysicsHandler.setVelocityX((-1) * this.mPhysicsHandler.getVelocityX());
}
}
super.onManagedUpdate(pSecondsElapsed);
}
谢谢你。