lundi 29 juin 2015

fire in every five seconds with libGdx


how do call fire method in every five seconds with libGdx ?

this is my Enemy class :

I wrote the following code, but it is wrong.

public class Enemy {

    private List<Bullet> bullets;
    private boolean isFire;

    public Enemy(){
        bullets=new ArrayList<Bullet>();
    }
    public void update(float delta) {
        Gdx.app.log("State", "State Fire");
        if(!isFire){
            Gdx.app.log("State", "Fire");
            fire();
        }else{
            Gdx.app.log("State", "No Fire");
        }
    }
    private void fire() {
        isFire=true;
        bullets.add(new Bullet(5, 32));
        Timer.schedule(new Task(){
            @Override
            public void run() {
                reload();
            }
        }, getDelay());
    }
    private void reload(){
        isFire=false;
    }
    private int getDelay() {
        return 5;
    }
    public List<Bullet> getBullets(){
        return bullets;
    }
}

Is there a way to solve the problem? I have no idea


Aucun commentaire:

Enregistrer un commentaire