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.