Java 舞台吸引一切
我一直想做的是在游戏屏幕的右上角有一个退出按钮,尽管绘制按钮所在的舞台给我带来了困难(参见代码中的注释) 这是我为退出按钮和阶段(resize())编写的代码: 其余的(在show()中)Java 舞台吸引一切,java,render,libgdx,stage,Java,Render,Libgdx,Stage,我一直想做的是在游戏屏幕的右上角有一个退出按钮,尽管绘制按钮所在的舞台给我带来了困难(参见代码中的注释) 这是我为退出按钮和阶段(resize())编写的代码: 其余的(在show()中) 有什么特别的技巧可以让舞台和落下的雨滴、水桶和文字一起呈现吗?我和我的朋友们都被难住了,在任何地方都找不到解决方案。在批处理后移动stage.draw().end()或在批处理前移动。begin()在我看来,这不是你采取的正确方法。如果您使用的是libgdx中的stage,那么您应该受益于Scene2d的其他
有什么特别的技巧可以让舞台和落下的雨滴、水桶和文字一起呈现吗?我和我的朋友们都被难住了,在任何地方都找不到解决方案。在批处理后移动stage.draw().end()或在批处理前移动。begin()在我看来,这不是你采取的正确方法。如果您使用的是libgdx中的stage,那么您应该受益于Scene2d的其他组件。因此,与其单独绘制雨滴和其他游戏实体(并使工作变得复杂),不如让它们成为演员,将它们添加到舞台上,然后在渲染中绘制舞台 例如:
atlas = new TextureAtlas("gamebuttons.pack");
skin = new Skin();
skin.addRegions(atlas);
text = new BitmapFont();
其他实体也是如此。初始化并将其添加到您的舞台
以下是官方维基,以了解更多信息:
你是说他的退出按钮吗?是的,我不明白为什么这之前没有被提升,除了它不是正确的答案。请尽量保持你的答案清晰,用正确的词代替“ur”,因为“ur”可能意味着你和你的家人。
if (stage == null)
stage = new Stage(width, height, true);
stage.clear();
Gdx.input.setInputProcessor(stage);
TextButtonStyle styleQuit = new TextButtonStyle();
styleQuit.up = skin.getDrawable("buttonnormal");
styleQuit.down = skin.getDrawable("buttonpressed");
styleQuit.font = text;
quitButton = new TextButton(" ", styleQuit);
quitButton.setWidth(128);
quitButton.setHeight(128);
quitButton.setX(800 - 128);
quitButton.setY(480 - 100);
quitButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
Gdx.app.log(RainCatcher.LOG, "Quit Button Pressed");
game.setScreen(new MainMenu(game));
}
});
stage.addActor(quitButton);
atlas = new TextureAtlas("gamebuttons.pack");
skin = new Skin();
skin.addRegions(atlas);
text = new BitmapFont();
public class RaindDrop extends Actor {
TextureRegion region;
public RaindDrop () {
region = new TextureRegion(...);
}
public void draw (SpriteBatch batch, float parentAlpha) {
Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
batch.draw(...);
}
}