方法停止被调用

时间:2015-07-02 03:52:32

标签: java libgdx

我创建了一个每次调用时创建一个对象的方法,当一个布尔变量等于true时,产生将停止,但是当我将该变量设置为false时,不再调用将生成我的字符的方法,我不明白,因为它在渲染方法上,所以它应该更新每一帧。

   public void update() {
            deltaTime = Gdx.graphics.getDeltaTime();
            timer += 1 * deltaTime;

            if(endGame==false) {  //when the game starts it works.
                if (timer >= rTime) {
                    newEnemy0();//this is the method for spawning
                    timer -= rTime;
                    rTime = rFloat.nextInt(3) + 1 * 1f;
                    rPosition1 = rFloat.nextInt(700) + 1;
                }
            }/*when a certain thing happen endGame==true, then when I click a button it will be back to false but when I put it back to false nothing happens*/


//this is the newRnemy method basically it just creates a new sprite using pools.
 public void newEnemy0(){
        Sprite enemy= Pools.obtain(Sprite.class);
        enemy.setSize(80,80);
        enemy.setPosition(rPosition1, 150);
        enemies.add(enemy);
    }



 //I just realized that endGame doesn't go back to false when I click a button:
 playButton.addListener(new InputListener(){
           @Override
           public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
               enemyObj.endGame=false;
               System.out.println(enemyObj.endGame);
               return super.touchDown(event, x, y, pointer, button);
           }
       });// this code is not updated every frame.

0 个答案:

没有答案