使用 andengine 我正在尝试创建一个足球游戏,当球进入球门并从屏幕上消失时,我想更新得分并将球重新定位在屏幕中央。更新分数在运作良好,但不是重新定位。这是球的代码:
final AnimatedSprite ball;
final Body bodyBall;
ball = new AnimatedSprite(centerX, centerY,this.mBallTextureRegion, this.getVertexBufferObjectManager());
bodyBall = PhysicsFactory.createBoxBody(this.mPhysicsWorld, ball, BodyType.DynamicBody, FIXTURE_DEF);
ball.setUserData(bodyBall);
ball.animate(200);
this.mScene.registerTouchArea(ball);
this.mScene.attachChild(ball);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(ball, bodyBall, true, true));
这里是检查目标的代码:
@Override
public void onUpdate(final float pSecondsElapsed) {
if(UpperGoal.collidesWith(ball)) {
ScoreA = ScoreA+1;
ScoreText.setText(ScoreA+" - " + ScoreB);
bodyBall.setTransform(new Vector2(CAMERA_WIDTH/2,CAMERA_HEIGHT/2),0);
UpperGoal.setColor(1, 0, 0);
我也尝试了 bodyBall.setPosition(100,100,0)。