プレイヤーのダイイベントの処理 という見出しの下にあるように、テキストオブジェクトをシーンにアタッチしようとしています http://www.matim-dev.com/full-game-tutorial---part-13.html
Player クラスを拡張する AnimatedSprite があります。私はプレーヤーを作成しました
mPlayer = new Player(x, y, resourceManager.getVertexBufferObjectManager(), resourceManager.getCamera(), mPhysicsWorld)
{
@Override
public void onDie() {
if (!gameOverDisplayed)
{
displayGameOverText();
}
}
};
displayGameOverText()
メソッドは次のように与えられます。
private void displayGameOverText()
{
mCamera.setChaseEntity(null);
gameOverText.setPosition(mCamera.getCenterX(), mCamera.getCenterY());
attachChild(gameOverText);
gameOverDisplayed = true;
}
createScene()
メソッドでgameOverTextも初期化しましたが、
gameOverText = new Text(0, 0, resourceManager.getFontArial(), "Game Over!", mVBOM);
この段階で、コードは正常に動作し、テキストゲーム オーバー! を呼び出すと表示されonDie()
ます。
しかし、onDie()
以下のようにメソッドを再設計すると、Text Game Over! 呼び出し時は表示されませんonDie()
。
@Override
public void onDie() {
if (!gameOverDisplayed)
{
mCamera.setChaseEntity(null);
gameOverText.setPosition(mCamera.getCenterX(), mCamera.getCenterY());
attachChild(gameOverText);
gameOverDisplayed = true;
}
}
コードが同じであるため、この動作は奇妙に思えます。唯一の違いは、後者のonDie()
方法でコードをインラインで指定したことです。
誰かがこの動作の原因を理解するのを手伝ってくれますか? これに関して logcat に書き込まれたログはありません。