Hi guys.
I will go directly to the point.
Whenever my missile hits the enemyplane, which are both two rectangles sprites. I want to create an explosion.
Whenever i create and and tell it to draw itself, it draws in a dif location than i told it to.
I mean, as far as i researched and studied, in libgdx the 0,0 stays in bottom left , as a cartesian graphic, right?
Well, it isnt working that. So heres what i did, i decided to load each texture separetly and draw it, still same error happens…
The weird thing is that, i tell it to draw exactly where the missile last pos were… So it should be in same place!
Can anyone give me a hand with this ? Its driving me nuts!
package Atlas;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author André Vinícius Lopes
*/
public class ExplosionLoader {
public Texture[] explosionsTextures;
//Should have used List instead but .. whatever
public List<Texture> textures;
public ExplosionLoader()
{
explosionsTextures = new Texture[48];
loadExplosionsTextures();
}
private void loadExplosionsTextures() {
explosionsTextures[0] = new Texture(Gdx.files.internal("ExplosionSheet_001.png"));
explosionsTextures[1] = new Texture(Gdx.files.internal("ExplosionSheet_002.png"));
explosionsTextures[2] = new Texture(Gdx.files.internal("ExplosionSheet_003.png"));
explosionsTextures[3] = new Texture(Gdx.files.internal("ExplosionSheet_004.png"));
explosionsTextures[4] = new Texture(Gdx.files.internal("ExplosionSheet_005.png"));
explosionsTextures[5] = new Texture(Gdx.files.internal("ExplosionSheet_006.png"));
explosionsTextures[6] = new Texture(Gdx.files.internal("ExplosionSheet_007.png"));
explosionsTextures[7] = new Texture(Gdx.files.internal("ExplosionSheet_008.png"));
explosionsTextures[8] = new Texture(Gdx.files.internal("ExplosionSheet_009.png"));
explosionsTextures[9] = new Texture(Gdx.files.internal("ExplosionSheet_010.png"));
explosionsTextures[10] = new Texture(Gdx.files.internal("ExplosionSheet_011.png"));
explosionsTextures[11] = new Texture(Gdx.files.internal("ExplosionSheet_012.png"));
explosionsTextures[12] = new Texture(Gdx.files.internal("ExplosionSheet_013.png"));
explosionsTextures[13] = new Texture(Gdx.files.internal("ExplosionSheet_014.png"));
explosionsTextures[14] = new Texture(Gdx.files.internal("ExplosionSheet_015.png"));
explosionsTextures[15] = new Texture(Gdx.files.internal("ExplosionSheet_016.png"));
explosionsTextures[16] = new Texture(Gdx.files.internal("ExplosionSheet_017.png"));
explosionsTextures[17] = new Texture(Gdx.files.internal("ExplosionSheet_018.png"));
explosionsTextures[18] = new Texture(Gdx.files.internal("ExplosionSheet_019.png"));
explosionsTextures[19] = new Texture(Gdx.files.internal("ExplosionSheet_020.png"));
explosionsTextures[20] = new Texture(Gdx.files.internal("ExplosionSheet_021.png"));
explosionsTextures[21] = new Texture(Gdx.files.internal("ExplosionSheet_022.png"));
explosionsTextures[22] = new Texture(Gdx.files.internal("ExplosionSheet_023.png"));
explosionsTextures[23] = new Texture(Gdx.files.internal("ExplosionSheet_024.png"));
explosionsTextures[24] = new Texture(Gdx.files.internal("ExplosionSheet_025.png"));
explosionsTextures[25] = new Texture(Gdx.files.internal("ExplosionSheet_026.png"));
explosionsTextures[26] = new Texture(Gdx.files.internal("ExplosionSheet_027.png"));
explosionsTextures[27] = new Texture(Gdx.files.internal("ExplosionSheet_028.png"));
explosionsTextures[28] = new Texture(Gdx.files.internal("ExplosionSheet_029.png"));
explosionsTextures[29] = new Texture(Gdx.files.internal("ExplosionSheet_030.png"));
explosionsTextures[30] = new Texture(Gdx.files.internal("ExplosionSheet_031.png"));
explosionsTextures[31] = new Texture(Gdx.files.internal("ExplosionSheet_032.png"));
explosionsTextures[32] = new Texture(Gdx.files.internal("ExplosionSheet_033.png"));
explosionsTextures[33] = new Texture(Gdx.files.internal("ExplosionSheet_034.png"));
explosionsTextures[34] = new Texture(Gdx.files.internal("ExplosionSheet_035.png"));
explosionsTextures[35] = new Texture(Gdx.files.internal("ExplosionSheet_036.png"));
explosionsTextures[36] = new Texture(Gdx.files.internal("ExplosionSheet_037.png"));
explosionsTextures[37] = new Texture(Gdx.files.internal("ExplosionSheet_038.png"));
explosionsTextures[38] = new Texture(Gdx.files.internal("ExplosionSheet_039.png"));
explosionsTextures[39] = new Texture(Gdx.files.internal("ExplosionSheet_040.png"));
explosionsTextures[40] = new Texture(Gdx.files.internal("ExplosionSheet_041.png"));
explosionsTextures[41] = new Texture(Gdx.files.internal("ExplosionSheet_042.png"));
explosionsTextures[42] = new Texture(Gdx.files.internal("ExplosionSheet_043.png"));
explosionsTextures[43] = new Texture(Gdx.files.internal("ExplosionSheet_044.png"));
explosionsTextures[44] = new Texture(Gdx.files.internal("ExplosionSheet_045.png"));
explosionsTextures[45] = new Texture(Gdx.files.internal("ExplosionSheet_046.png"));
explosionsTextures[46] = new Texture(Gdx.files.internal("ExplosionSheet_047.png"));
explosionsTextures[47] = new Texture(Gdx.files.internal("ExplosionSheet_048.png"));
}
}
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;
/**
*
* @author André Vinícius Lopes
*/
public class Explosion {
private Texture currentFrame; //
private SpriteManager spriteManager; //
private int posX, posY;
private int indexFrame;
public Explosion(SpriteManager sm, int posX, int posY) {
spriteManager = sm;
//
this.posX = posX;
this.posY = posY;
//
indexFrame = 0;
}
public void update() {
indexFrame++;
if (indexFrame >= spriteManager.getExplosionLoader().explosionsTextures.length) {
indexFrame = 0;
}
currentFrame = spriteManager.getExplosionLoader().explosionsTextures[indexFrame];
}
public void render(SpriteBatch sb) {
if (currentFrame == null) {
update();
}
sb.draw(currentFrame, posX, posY);
}
public boolean isFinished() {
if (indexFrame > 30) {
return true;
} else {
return false;
}
}
}