How to manage several Explosions Drawing/Happening ?

Heya.
I kept thinking and thinking and thinking but i still dont know the better way to create a class/method/functions to manage several explosions happening.
I mean the drawing and some kind of ArrayList to control them, also, idk how to create a flag using this class here, to know when the drawing finished…

soo, if anyone could at least tell me what i need to research , i dont want to abuse anyone to give me the answer, but if you can atleast point me to the right direction, i would appreciate a looooot.

Heres the class that im using, i got here from a friend, i think from 65k user?

Anyway, here it is :

package Atlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import java.util.ArrayList;

public class Explosions {

    private static final int FRAME_COLS = 8;
    private static final int FRAME_ROWS = 6;
    Animation walkAnimation;
    Texture walkSheet;
    TextureRegion[] walkFrames;
    SpriteBatch spriteBatch;
    TextureRegion currentFrame;
    float stateTime;

    private ArrayList<Explosions> explosionsHappening;
    private int posx,posy;
    private int TEXTURE_WIDTH,TEXTURE_HEIGHT;
    
    public Explosions() {
        explosionsHappening = new ArrayList<>();
        walkSheet = new Texture(Gdx.files.internal("Explosion2spritesheet.png"));

        TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS);

        walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
        int index = 0;
        for (int i = 0; i < FRAME_ROWS; i++) {
            for (int j = 0; j < FRAME_COLS; j++) {
                walkFrames[index++] = tmp[i][j];
            }
        }

        walkAnimation = new Animation(0.025f, walkFrames);
        spriteBatch = new SpriteBatch();
        stateTime = 0f;
        
        
        //Width ¨¨ Height
        TEXTURE_WIDTH = (walkSheet.getWidth() / FRAME_COLS);  
        TEXTURE_HEIGHT = (walkSheet.getHeight() / FRAME_ROWS);
        
    }
   
    
    public TextureRegion getCurrentFrame()
    {
        stateTime += Gdx.graphics.getDeltaTime();                  
        currentFrame = walkAnimation.getKeyFrame(stateTime,false);  
        
        return currentFrame;
    }

    public ArrayList<Explosions> getExplosionsHappening() {
        return explosionsHappening;
    }

    public void addExplosionsHappening(Explosions exp,int posX,int posY) {
        exp.posx = posX;
        exp.posy = posY;
        explosionsHappening.add(exp);
        
        System.out.println("Explosion [x] :" + exp.posx);
        System.out.println("Explosion [y] :" + exp.posy);
    }

    public int getPosx() {
        return posx;
    }

    public int getPosy() {
        return posy;
    }

    public int getTEXTURE_WIDTH() 
    {
     return TEXTURE_WIDTH;
    }

    public int getTEXTURE_HEIGHT() 
    {
     return TEXTURE_HEIGHT;
    }
    
    
    
    
    
}

I cleaned the class a little, to go back to the original.

Heres the result :

package Atlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Explosions {

    private static final int FRAME_COLS = 8;
    private static final int FRAME_ROWS = 6;
    Animation walkAnimation;
    Texture walkSheet;
    TextureRegion[] walkFrames;
    SpriteBatch spriteBatch;
    TextureRegion currentFrame;
    float stateTime;

    private int textureWidth,textureHeight;
    
    public Explosions() {
      
        walkSheet = new Texture(Gdx.files.internal("Explosion2spritesheet.png"));

        TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS);

        walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
        int index = 0;
        for (int i = 0; i < FRAME_ROWS; i++) {
            for (int j = 0; j < FRAME_COLS; j++) {
                walkFrames[index++] = tmp[i][j];
            }
        }

        walkAnimation = new Animation(0.025f, walkFrames);
        spriteBatch = new SpriteBatch();
        stateTime = 0f;
        
        //Width ¨¨ Height
        textureWidth = (walkSheet.getWidth() / FRAME_COLS);  
        textureHeight = (walkSheet.getHeight() / FRAME_ROWS);
        
    }
   
    
    public TextureRegion getCurrentFrame()
    {
        stateTime += Gdx.graphics.getDeltaTime();                  
        currentFrame = walkAnimation.getKeyFrame(stateTime,false);  
        
        return currentFrame;
    }


    public int getTextureWidth() 
    {
     return textureWidth;
    }

    public int getTextureHeight() 
    {
     return textureHeight;
    }
    
    
    
    
    
}

So , i have some ideas…
One would make this class as a model, and create an explosion class and create an arrayList at gameupdate with the state and explosions positions, and keep drawing…

Well, i guess thats the only idea.

Btw, should i make an Atlas for just this img ?

I don’t think I fully understand your question but here goes:

  1. You need a class a class for your entity that is set up generally like this:
public Explosion (double x, double y){
this.x = x;
this.y = y;
}

public void update(){
//make a timer so the explosion will fade away or you can make it move... whatever you need
}

public void render(){
drawImage()//the function that actually draws your object
}

Then you need a class like a map or something, where you update and render all your entities. You will need a way to store your entities, most common is an arraylist for the obvious reasons. And you will need two main methods, one for drawing and one for updating. It will look something like this:

ArrayList<//your entity> entityList;

public Game(){
//init all your objects
	entityList = new ArrayList<//your entity>();
}

public void update(){
for (int i = 0; i < entityList.size(); i++){
	entityList.get(i).update();
     }
}

public void render(){
for (int i = 0; i < entityList.size(); i++){
	entityList.get(i).render();
     }
}

}


Now, again I have no idea if this is what you mean, so sorry if it isn’t!

Have you thought about using particles? :slight_smile:
https://code.google.com/p/libgdx/wiki/ParticleEditor

Thats exactly what i needed.
I will think about that in “tha” morning. And lets see what the sun will bring :stuck_out_tongue:

TY !!!

Alright, i followed your instructions and it worked like a charm.
Its way faster now, and it isnt bugging. Also, i figured it out how to check that is the last animation frame, so i can remove from the list.

 public boolean isFinished()
    {
       return explosionAnimation.isAnimationFinished(stateTime);
    }

TY :smiley: