i am trying to create random bullets but it is not working for some reason. also how can i make a delay so the bullets come every 30 seconds or 1 minute????
also the onTouch method does not work and it is not taking the bullet away????
shall i put the array in the GameRender class?
thanks
public class GameWorld {
public static Ball ball;
private Bullet bullet1;
private ScrollHandler scroller;
private Array<Bullet> bullets = new Array<Bullet>();
public GameWorld() {
ball = new Ball(280, 273, 32, 32);
bullet = new Bullet(-300, 200);
scroller = new ScrollHandler(0);
bullets.add(new Bullet(bullet.getX(), bullet.getY()));
bullets = new Array<Bullet>();
Bullet bullet = null;
float bulletX = 0.0f;
float bulletY = 0.0f;
for (int i=0; i < 10; i++) {
bulletX = MathUtils.random(-10, 10);
bulletY = MathUtils.random(-10, 10);
bullet = new Bullet(bulletX, bulletY);
bullets.add(bullet);
}
}
public void update(float delta) {
ball.update(delta);
bullet.update(delta);
scroller.update(delta);
}
public static Ball getBall() {
return ball;
}
public ScrollHandler getScroller() {
return scroller;
}
public Bullet getBullet1() {
return bullet1;
}
}
i also tried this and it is not working, i used this in the GameRender class
Array<Bullet> enemies=new Array<Bullet>();
//in the constructor of the class
enemies.add(new Bullet(bullet.getX(), bullet.getY()));
// this throws an exception for some reason??? this is in the render method
for(int i=0; i<bullet.size; i++)
bullet.get(i).draw(batcher);
//this i am using in any method that will allow me from the constructor to update to render
for(int i=0; i<bullet.size; i++)
bullet.get(i).update(delta);
this is not taking the bullet out
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
for(int i=0; i<bullet.size; i++)
if(bullet.get(i).getBounds().contains(screenX,screenY))
bullet.removeIndex(i--);
return false;
}
thanks for the help anyone.