I added an ability to shoot in the game, and even though it works great, for some reason a bullet texture will appear above the sprite between every shot. It ends up looking like this:
I am looking through my code but I can't find anything that would draw that texture there. The texture's position is set to draw on the bullet body and no bullet body appears up there. Any idea why this texture is spawning up there? Any help is appreciated.
This is my bullet class:
public bullet(playScreen screen, float x, float y, boolean fireRight){
this.fireRight = fireRight;
this.screen = screen;
this.world = screen.getWorld();
tearPopAtlas = new TextureAtlas("tear_pop.pack");
frames = new Array<TextureRegion>();
for(int i = 0; i < 5; i++){
frames.add(new TextureRegion(tearPopAtlas.findRegion("tear_pop"), i * 32, 0, 64, 64));
}
for(int i = 0; i < 5; i++){
frames.add(new TextureRegion(tearPopAtlas.findRegion("tear_pop"), i * 32, 32, 64, 64));
}
for(int i = 0; i < 5; i++){
frames.add(new TextureRegion(tearPopAtlas.findRegion("tear_pop"), i * 32, 64, 64, 64));
}
bulletDestroyedAnimation = new Animation<TextureRegion>(0.1f, frames);
setRegion(bulletDestroyedAnimation.getKeyFrame(0));
setBounds(x, y, 32 / icsGame.PPM, 32 / icsGame.PPM);
defineBullet();
}
public void defineBullet(){
FixtureDef fdef;
CircleShape shape;
BodyDef bdef = new BodyDef();
bdef.position.set(fireRight ? getX() + 0.05f / icsGame.PPM : getX() - 0.05f, getY());
bdef.type = BodyDef.BodyType.DynamicBody;
if(!world.isLocked())
b2Body = world.createBody(bdef);
fdef = new FixtureDef();
shape = new CircleShape();
shape.setRadius(3 / icsGame.PPM);
fdef.filter.categoryBits = icsGame.BULLET_BIT;
fdef.filter.maskBits = icsGame.DEAFAULT_BIT | icsGame.ENEMY_BIT | icsGame.DOOR_BIT;
fdef.shape = shape;
fdef.friction = 0;
b2Body.createFixture(fdef).setUserData(this);
b2Body.setLinearVelocity(new Vector2(fireRight ? 2f : -2f, 0));
}
public void update(float dt){
stateTime += dt;
setPosition(b2Body.getPosition().x - getWidth() / 2, b2Body.getPosition().y - getHeight() / 2);
if((stateTime > 1 || setToDestroy) && !destroyed){
world.destroyBody(b2Body);
destroyed = true;
}
if((fireRight && b2Body.getLinearVelocity().x < 0) || (!fireRight && b2Body.getLinearVelocity().x > 0)){
setToDestroy();
}
}
public void setToDestroy(){
setToDestroy = true;
}
public boolean isDestroyed(){
return destroyed;
}
}
This is how I draw the bullets in another class:
for(bullet bullet : bullets){
bullet.update(dt);
if(bullet.isDestroyed())
bullets.removeValue(bullet, true);
}
if(currentStateShooting == State.EASTWEST && shootTimer >= SHOOT_WAIT_TIME) {
shootTimer = 0;
fire();
}
public void fire(){
bullets.add(new bullet(screen, isaac.ISAACX, isaac.ISAACY, shootingRight ? true : false));
}
public void draw(Batch batch){
super.draw(batch);
for(bullet bullet : bullets){
bullet.draw(batch);
}
}
These are all the pieces of code involved with my bullet and I can't figure out why that bullet texture is getting drawn where it is.
