我正在尝试创建一个会在玩家移动时更新的进度条。现在我只想让进度条显示在屏幕上。我似乎无法弄清楚它为什么没有出现 屏幕上。玩家精灵表演,但不是进度条。 TIA!
以下是使用进度条的Stamina Bar类:
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){
}
}
这是Renderer类:
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 :(得分:0)
可能因为你不能画它。你在渲染中声明它,你应该在Create中做。 我设法让进度条工作,但后来我使用了一个舞台,将它添加到舞台上。您必须将其添加到批次中。