嘿大家我对libgdx和Open GL都很陌生,所以我遇到了这个我必须做的示例项目的问题。这是我的代码,应该只是显示.batch文件中的三个按钮,非常感谢任何帮助。经过调试器之后,我唯一能看到的是调用get draw能够返回对象[o],但如果它没有找到任何原因,那么它是否会出错?
public MainScreen() {
spriteBatch = new SpriteBatch();
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, spriteBatch);
font = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
Gdx.files.internal("assets/font.png"), false);
buttons = new TextureAtlas("assets/GameButtons.pack");
images = new Skin();
images.addRegions(buttons);
SFXButton = new Button(images.getDrawable("sfxButton"));
SFXButton.setPosition(295, 310);
APIButton = new Button(images.getDrawable("apiButton"));
APIButton.setPosition(405, 310);
GameButton = new Button(images.getDrawable("gameButton"));
GameButton.setPosition(515, 310);
SFXClick = Gdx.audio.newSound(Gdx.files.internal("assets/button_click.wav"));
}
@Override
public void dispose() {
spriteBatch.dispose();
stage.dispose();
}
@Override
public void render(float delta) {
stage.act(delta);
stage.draw();
stage.addActor(SFXButton);
stage.addActor(APIButton);
stage.addActor(GameButton);
spriteBatch.begin();
font.setColor(Color.RED);
font.draw(spriteBatch, "PennyPop", 455 - font.getBounds("PennpyPop").width/2,
460 + font.getBounds("PennyPop").height/2);
if (SFXButton.isPressed())
SFXClick.play();
spriteBatch.end();
}
答案 0 :(得分:0)
OUCH! 你想要为你的舞台每个渲染添加按钮,有60个FPS和3个按钮,可以添加180个按钮到你的舞台每秒,每秒一次,直到你关闭你的应用程序。
public void render(float delta) {
stage.act(delta);
stage.draw();
stage.addActor(SFXButton); //problem here
stage.addActor(APIButton); //and here
stage.addActor(GameButton); //and here
移动按钮添加到构造函数,看看它是否能解决问题。