我正在使用 AndEngine 创建一个简单的游戏。我有以恒定速度移动的精灵。当精灵撞墙或在接触点相互碰撞时,我需要能够显示点 (+1)、(+2) 等。如何使用文本做到这一点?
我正在使用 AndEngine 示例“MovingBallExample.java”的修改版本。下面的代码显示了球在撞到墙上时如何反转方向。我需要在接触点显示文本,最好在一个圆圈中显示几秒钟。
private static class Ball extends AnimatedSprite {
private final PhysicsHandler mPhysicsHandler;
public Ball(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.mPhysicsHandler = new PhysicsHandler(this);
this.registerUpdateHandler(this.mPhysicsHandler);
this.mPhysicsHandler.setVelocity(BALL_VELOCITY, BALL_VELOCITY);
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
if(this.mX < 0) {
this.mPhysicsHandler.setVelocityX(BALL_VELOCITY);
} else if(this.mX + this.getWidth() > CAMERA_WIDTH) {
//**** Need to add Points text here **********/
this.mPhysicsHandler.setVelocityX(-BALL_VELOCITY);
}
if(this.mY < 0) {
this.mPhysicsHandler.setVelocityY(BALL_VELOCITY);
} else if(this.mY + this.getHeight() + 80 > CAMERA_HEIGHT) {
//**** Need to add Points text here **********/
this.mPhysicsHandler.setVelocityY(-BALL_VELOCITY);
}
欢迎任何和所有想法。