Hi,
I cannot for the life of me see why my sprite isn’t being rendered, this is the code:
public class Bullet {
private Texture bullet = null;
private Sprite spriteBullet = null;
private boolean firing;
public Sprite getBullet() { return spriteBullet; }
private double x1,y1,distance,angleToPlayer;
public Bullet()
{
firing = false;
if(bullet==null) {
bullet = new Texture(Gdx.files.internal("assets/data/bullet.png"));
}
spriteBullet = new Sprite(bullet);
}
public void fireBullet(float x, float y, float tx, float ty, SpriteBatch batch)
{
if(!firing)
{
x1 = Math.pow(Math.abs(x) - Math.abs(tx),2);
y1 = Math.pow(Math.abs(y) - Math.abs(ty),2);
distance = Math.sqrt(x1 + y1);
angleToPlayer = Math.atan2(Math.abs(y-ty), Math.abs(x-tx));
firing = true;
}
spriteBullet.setPosition(x, y);
spriteBullet.draw(batch);
}
}
fireBullet is called from within main game loop where the projection matrix is fine (set to camera), batch is fine and the x,y positions above are correct. All my other sprites etc are drawn, just this one refuses and the method is called every frame?
Another second pair of eyes may help?!
Thanks