2014-12-04 55 views
0

我正在嘗試創建一個進度條,隨着玩家的移動進行更新。現在我只是想讓進度條出現在屏幕上。我似乎無法弄清楚爲什麼屏幕上不出現 。玩家精靈顯示,但不是進度條。蒂亞!libgdx progressbar沒有顯示在主屏幕上

下面是使用進度欄的耐力酒吧類:

import javax.swing.JFrame; 
import javax.swing.JProgressBar; 

import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.Texture; 
import com.badlogic.gdx.graphics.g2d.TextureRegion; 
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar; 
import com.badlogic.gdx.scenes.scene2d.ui.Widget; 
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 

public class StaminaBar extends Widget implements Updatable { 

    public ProgressBar pb; 
    public Texture progress_bar = new Texture(Gdx.files.internal("assets/pb.jpg")); 
    public Texture pb_knob = new Texture(Gdx.files.internal("assets/bat_knob.jpg")); 
    public ProgressBar.ProgressBarStyle pbs = new ProgressBar.ProgressBarStyle(); 



    public StaminaBar(){ 


    pbs.background = new TextureRegionDrawable(new TextureRegion(progress_bar)); 
     pbs.knob = new TextureRegionDrawable(new TextureRegion(pb_knob)); 

     pb = new ProgressBar(0f, 60f, 3f, true, pbs); 
     pb.setValue(58); 
     pb.setPosition(0, 0); 
     pb.setVisible(true); 
     pb.setSize(40f, 100f); 
     pb.validate(); 


    } 


    @Override 
    public void update(float d){ 


    } 


} 

下面是渲染器類:

import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.Camera; 
import com.badlogic.gdx.graphics.OrthographicCamera; 
import com.badlogic.gdx.graphics.Texture; 
import com.badlogic.gdx.graphics.g2d.BitmapFont; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
import com.badlogic.gdx.graphics.g2d.TextureRegion; 
import com.badlogic.gdx.maps.tiled.TiledMap; 
import com.badlogic.gdx.maps.tiled.TiledMapRenderer; 
import com.badlogic.gdx.maps.tiled.TmxMapLoader; 
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; 
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar; 
import com.badlogic.gdx.scenes.scene2d.ui.Widget; 
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 

import edu.groupa.gameobjects.GameObject; 
import edu.groupa.gameobjects.StaminaBar; 


public class Renderer { 

    private SpriteBatch spriteBatch; 
    private Controller control; 


    //Texture bg1; 
    //private float bg1Xpos; 

    public Renderer(Controller c){ 
     control = c; 
     spriteBatch = new SpriteBatch(); 

    } 
    public void render(){ 

     StaminaBar st = new StaminaBar(); 


     spriteBatch.begin(); 

     // Call all the draws of the individual objects here 
     for(GameObject gObj : control.getDrawableObjects()){ 
      gObj.sprite.draw(spriteBatch); 
     } 

     spriteBatch.end(); 

    } 
+0

最後,我需要從Stage類聲明Stage對象,然後將ProgressBar添加到舞臺上。 – Tammytee 2014-12-07 04:13:29

回答

0

可能是因爲你不畫它。你在渲染中聲明它,你應該在Create中做。 我設法讓進度條工作,但後來我使用了一個舞臺,將它添加到舞臺上並繪製舞臺。您將不得不將其添加到該批次中。