Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm in process of developing simple android puzzle game. I decided to choose andEngine as an engine for my game.

In my game I have a gameField [][] array, which represents a game field, where each element is a cell of game level and consists of a type of the cell (for ex. FLOOR of WALL). During the game, state of cell can be changed (for ex. DOOR_CLOSED changed to DOOR_OPENED), but it happens rarely, almost all the elements of gameField don't change.

I tried to implement that by adding repaint method to updateHandler, which would paint sprites for each cell every tick. But I wonder wouldn't be that approach a wasting of memory and processor time? What is the best practise for doing that?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

How about having that multidimensional array of yours filled with, say, an extension of TiledSprites. Something like the following:

public class Door extends TiledSprite {

    private boolean isOpen = false;
    private static final int DOOR_CLOSED = 0;
    private static final int DOOR_OPEN = 1;

    public Door() {
        this(0, 0, doorTextureRegion, vertexBufferObjectManager);
        this.setCurrentTileIndex(DOOR_CLOSED);
    }

    public open() {
        this.isOpen = true;
        this.setCurrentTileIndex(DOOR_OPEN);
    }

    public close() {
        this.isOpen = false;
        this.setCurrentTileIndex(DOOR_CLOSE);
    }

}

In your scene, you attach all the TiledSprites as children of the scene. Iterate over the array in an initialization method, say. You shouldn't have to constantly poll and redraw--AndEngine takes care of that for you.

share|improve this answer
    
I just saw your answer :) Thanks for reply, I've already implement similar approach in my game :) –  mol Jun 20 '13 at 8:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.