有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 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();

    }

共 (1) 个答案

  1. # 1 楼答案

    可能是因为你没有画。您可以在render中声明它,这应该在Create中执行。 我设法让progressbar工作,但后来我使用了一个舞台,将它添加到舞台上并绘制舞台。您必须将其添加到批次中