如何将纹理图像按钮链接到另一个屏幕?

huangapple go评论58阅读模式
英文:

How do i link a Texture image button to another screen?

问题

  1. 如何设置"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

我会假设playbuttonActiveexitbutton是在屏幕上绘制的纹理。如果是这样的话,你只需要检查屏幕上的触摸位置:

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

huangapple
  • 本文由 发表于 2023年2月14日 02:02:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定