Skip to content

Commit

Permalink
Fixes due to Entity.getChildByXYZ changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Gramlich committed Apr 20, 2012
1 parent 1860c19 commit cae0fa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void drawUsingSpriteBatch(final Scene pScene) {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
final int randomChildIndex = AttachDetachBenchmark.this.mRandom.nextInt(spriteGroup.getChildCount());
final Sprite child = (Sprite)spriteGroup.getChild(randomChildIndex);
final Sprite child = (Sprite)spriteGroup.getChildByIndex(randomChildIndex);
child.detachSelf();
spriteGroup.attachChild(child);
}
Expand Down
14 changes: 7 additions & 7 deletions src/org/andengine/examples/game/snake/SnakeGameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,26 @@ public Scene onCreateScene() {

/* No background color needed as we have a fullscreen background sprite. */
this.mScene.setBackgroundEnabled(false);
this.mScene.getChild(LAYER_BACKGROUND).attachChild(new Sprite(0, 0, this.mBackgroundTextureRegion, this.getVertexBufferObjectManager()));
this.mScene.getChildByIndex(LAYER_BACKGROUND).attachChild(new Sprite(0, 0, this.mBackgroundTextureRegion, this.getVertexBufferObjectManager()));

/* The ScoreText showing how many points the pEntity scored. */
this.mScoreText = new Text(5, 5, this.mFont, "Score: 0", "Score: XXXX".length(), this.getVertexBufferObjectManager());
this.mScoreText.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
this.mScoreText.setAlpha(0.5f);
this.mScene.getChild(LAYER_SCORE).attachChild(this.mScoreText);
this.mScene.getChildByIndex(LAYER_SCORE).attachChild(this.mScoreText);

/* The Snake. */
this.mSnake = new Snake(Direction.RIGHT, 0, CELLS_VERTICAL / 2, this.mHeadTextureRegion, this.mTailPartTextureRegion, this.getVertexBufferObjectManager());
this.mSnake.getHead().animate(200);
/* Snake starts with one tail. */
this.mSnake.grow();
this.mScene.getChild(LAYER_SNAKE).attachChild(this.mSnake);
this.mScene.getChildByIndex(LAYER_SNAKE).attachChild(this.mSnake);

/* A frog to approach and eat. */
this.mFrog = new Frog(0, 0, this.mFrogTextureRegion, this.getVertexBufferObjectManager());
this.mFrog.animate(1000);
this.setFrogToRandomCell();
this.mScene.getChild(LAYER_FOOD).attachChild(this.mFrog);
this.mScene.getChildByIndex(LAYER_FOOD).attachChild(this.mFrog);

/* The On-Screen Controls to control the direction of the snake. */
this.mDigitalOnScreenControl = new DigitalOnScreenControl(0, CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight(), this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, this.getVertexBufferObjectManager(), new IOnScreenControlListener() {
Expand Down Expand Up @@ -228,14 +228,14 @@ public void onTimePassed(final TimerHandler pTimerHandler) {
titleText.setPosition((CAMERA_WIDTH - titleText.getWidth()) * 0.5f, (CAMERA_HEIGHT - titleText.getHeight()) * 0.5f);
titleText.setScale(0.0f);
titleText.registerEntityModifier(new ScaleModifier(2, 0.0f, 1.0f));
this.mScene.getChild(LAYER_SCORE).attachChild(titleText);
this.mScene.getChildByIndex(LAYER_SCORE).attachChild(titleText);

/* The handler that removes the title-text and starts the game. */
this.mScene.registerUpdateHandler(new TimerHandler(3.0f, new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
SnakeGameActivity.this.mScene.unregisterUpdateHandler(pTimerHandler);
SnakeGameActivity.this.mScene.getChild(LAYER_SCORE).detachChild(titleText);
SnakeGameActivity.this.mScene.getChildByIndex(LAYER_SCORE).detachChild(titleText);
SnakeGameActivity.this.mGameRunning = true;
}
}));
Expand Down Expand Up @@ -278,7 +278,7 @@ private void handleNewSnakePosition() {

private void onGameOver() {
this.mGameOverSound.play();
this.mScene.getChild(LAYER_SCORE).attachChild(this.mGameOverText);
this.mScene.getChildByIndex(LAYER_SCORE).attachChild(this.mGameOverText);
this.mGameRunning = false;
}

Expand Down

0 comments on commit cae0fa9

Please sign in to comment.