我試圖將圖像(playBtn)置於屏幕中央,下方的代碼更接近右上角。請參閱下面如何將圖像置於屏幕中心
public class FlappyBird extends ApplicationAdapter {
Texture img;
public static final int WIDTH = 1440;
public static final int HEIGHT = 2560;
}
我上面的代碼,我有我的設置寬度&高度,我相信是不這樣做的正確方法。儘管如此,這給了我所需要的值,但我似乎無法與playbth工作,並將其放置在中心
public class MenuState extends State {
private Texture background;
private Texture playBtn;
public MenuState(GameStateManager gsm) {
super(gsm);
background = new Texture("bg.png");
playBtn = new Texture("playbtn.png");
}
@Override
public void render(SpriteBatch sb) {
sb.begin();
sb.draw(background, 0, 0, FlappyBird.WIDTH, FlappyBird.HEIGHT);
//sb.draw(playBtn, (FlappyBird.WIDTH/2) - (playBtn.getWidth()/2), FlappyBird.HEIGHT/2);
sb.draw(playBtn,(FlappyBird.WIDTH/2)-(playBtn.getWidth()),FlappyBird.HEIGHT/2);
sb.end();
}
}
「不起作用」是什麼意思?它有什麼作用?它應該做什麼呢? – alzee
圖像未位於中央。它更靠右上方 – choman