英文:
How do i link a Texture image button to another screen?
问题
- 如何设置"playbuttonactive"在点击纹理时转到游戏屏幕,而"exitbtn"纹理会退出游戏?
英文:
1) How do I set the "playbuttonactive" to go to the gamescreen upon clicking on the texture and as for "exitbtn" texture would be exiting the game?
答案1
得分: 1
我会假设playbuttonActive
和exitbutton
是在屏幕上绘制的纹理。如果是这样的话,你只需要检查屏幕上的触摸位置:
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); // 获取输入事件的位置
camera.unproject(touchPos); // 将屏幕坐标转换为世界坐标
if (isWithinPlayButtonActiveCoordinates(touchPos)) {
// 切换到游戏界面
game.setScreen(new GameScreen(game));
dispose();
}
else if (isWithinExitButtonCoordinates(touchPos)) {
// 关闭应用程序
Gdx.app.exit();
}
}
希望这对你有所帮助。
英文:
I'll assume that playbuttonActive
and exitbutton
are textures that are drawn on the screen. If that's the case you just need to check where the screen was touched:
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); // get the position of the input event
camera.unproject(touchPos); // converts screen coordinates to world coordinates
if (isWithinPlayButtonActiveCoordinates(touchPos)) {
// change to the game screen
game.setScreen(new GameScreen(game));
dispose();
}
else if (isWithinExitButtonCoordinates(touchPos)) {
// close the application
Gdx.app.exit();
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论