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.

This is my first android game, sorry if my code is bad, any advice will help. I am trying to find ways to improve performance on a game of mine, I'm using AndEngine GLES2. I have a basic question about how to actually load sprites.

I have 6 player sprites that actually use the same jpg as it's image, the way I've been loading them is like this:

private void loadLinebackers(String imageResource, int i) {
    this.playersTextureAtlas[i] = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR);
    this.playersTextureRegion[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.playersTextureAtlas[i], this, imageResource, 0, 0);
    this.playersTextureAtlas[i].load();
}

private void loadWideReceivers(String imageResource, int i) {
    this.wrsTextureAtlas[i] = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR);
    this.wrsTextureRegion[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.wrsTextureAtlas[i], this, imageResource, 0, 0);
    this.wrsTextureAtlas[i].load();
}

Do I have to create an atlas and a region for every player that I have? Or can I somehow use the same resource?

All the players are viewable simultaneously within the camera. I run these load* functions via a for loop, passing in i each time.

Each set of players is performing different actions (SequenceModifiers) and I make the Sprite arrays like this:

private void makeLinebackers(Scene scene, float posX, float posY, int i, int spaceBetween) {
    this.olineman[i] = new Sprite(posX + (spaceBetween * i), posY, this.playersTextureRegion[i], this.getVertexBufferObjectManager());
    this.olinemenPhysicsHandler[i] = new PhysicsHandler(this.olineman[i]);
    this.olineman[i].registerUpdateHandler(this.olinemenPhysicsHandler[i]);
    scene.attachChild(this.olineman[i]);
}

private void makeWideReceivers(Scene scene, float posX, float posY, int i, int spaceBetween) {
    this.wideReceivers[i] = new Sprite(posX + (spaceBetween * i), posY, this.wrsTextureRegion[i], this.getVertexBufferObjectManager());
    this.wrsPhysicsHandler[i] = new PhysicsHandler(this.wideReceivers[i]);
    this.wideReceivers[i].registerUpdateHandler(this.wrsPhysicsHandler[i]);
    scene.attachChild(this.wideReceivers[i]);
}

I made each of these 2 different arrays, because generally each player from each array are doing similar animations and actions. For example, I make all the wide-receivers "run" at once.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If every player uses the same frames, create an instance of each unique graphic in texture memory, just as you suggest. That's all you need. When OpenGL renders textures to screen, all it's doing is reading those bytes from texture memory and copying them onto the default framebuffer (screen) after interpolation, perspective projection or whatever else is applicable in the render pipeline. So why copy from more than one source, if you can just copy from one, right?

(I don't know AndEngine so you'll have to figure out the basic how, but I'm sure it's fairly straightforward since this is how all GPU rendering works: AndEngine will be built accordingly.)

share|improve this answer
1  
Yep thanks for the advice, it appears one can "clone" a texture region. Instead of re-creating them each time. Hopefully, this is using the same resource each time, like you suggest. –  SSH This Jan 3 '13 at 21:09

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.