什么阻止我的屏幕按计划渲染?

时间:2015-02-26 02:58:25

标签: java multithreading libgdx

@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,1); 
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

combattext.setText(combatstring);



stage.act();
stage.draw();    
}

combatstring是一个字符串,显示我游戏中发生的事情。当敌人发动攻击时,它会说发生了什么。当我攻击时,它会说会发生什么。截至目前,我的游戏在战斗中有一个循环,运行转向计数实例。当转弯的时间到来时,参与者会转弯,当转弯结束时,它会更新战斗线。

我有2个combatstrings。一个是我的角色,一个是敌人。以下是一个敌人转身时会发生什么的例子。

if(thisencounter.monster1turn){  //monster1's turn goes in here

    thiscombat.getTarget(1);     //get enemy's target

    thiscombat.calculateVars(1); //calculate all combat variables for
                                 // this turn
    thiscombat.theyAttack();    

    combatstring = thisencounter.thisenemy.species+
                   " "+thiscombat.action+
                   " "+thiscombat.theirtarget.species+
                   " for "+thiscombat.effect;

    thisencounter.monster1turn=false;

}    

这很好用,我的战斗文字标签会在怪物出现时立即更新。

对于我的角色,他们的轮流使我的屏幕上显示按钮。按钮具有确定操作的侦听器,这是一个示例:

    monster1.addListener(new ClickListener(){ //makes the first enemy's 
                                              //image clickable, but only 
                                              //when the attack button 
                                              //has been clicked
    @Override
    public void clicked(InputEvent event, float x, float y) {

    thiscombat.ChooseTarget(1); //various methods that calculate damage,
                                //output what happened, and put us back in 

    thiscombat.calculateVars(4); //the loop to wait for next 
                                 //participant's turn
    thiscombat.youAttack();

    combatstring = thisencounter.thisspirit.species+
                   " "+thiscombat.action+
                   " "+thiscombat.yourtarget.species+
                   " for "+thiscombat.effect;

    monster1.clear();
    monster2.clear();
    monster3.clear();


        try {
            combatloop();
        } catch (InterruptedException ex) {
            Logger.getLogger(map1field.class.getName()).
                             log(Level.SEVERE, null, ex);
        }

   }});

这也很好,除了怪物前的转弯之外。由于在我的回合和怪物的转弯之间没有等待,因此战斗文本会立即显示怪物的行为。

我假设噢,这是因为两个回合之间没有延迟。所以,我在更新怪物combatstring的地方之前扔了一个thread.sleep(2000)。

但这并不能解决问题。它仍然没有显示我的角色在怪物面前的文字。此外,由于在游戏中进入此屏幕时就开始战斗,它会在屏幕上显示任何内容之前等待大约2秒钟。

对于我的生活,我不明白为什么它会像这样。有人能解释发生在我身上的事吗?是因为它在进入thread.sleep之前没有渲染吗?

如果是这样的话,如何强制它在thread.sleep之前渲染,或者我应该使用什么而不是thread.sleep?

0 个答案:

没有答案
相关问题