有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java游戏循环和方法调用

我正在用libgdx做一个2d游戏

澄清问题 我的代码如下所示:

public Class Game(){

      public void Mainloop{
         update();//to update some values
         render();//to render the values on the screen
      }


      public int showmessageOnthescreen(List<String> listOfChoice){

      }

    }

正如您所知,游戏循环不会进行stp渲染

有时会调用ShowMessageOnScreen,要求用户从字符串列表中选择一个字符串

我的问题是如何让用户从列表中进行选择


共 (1) 个答案

  1. # 1 楼答案

    how can check if the method was called to put the message on the screen

    在第一次调用该方法时设置一些布尔值

    how can i return a value

    通过写return someValue;

    how can i call the method from outside and in the same time the loop has to update and show the screen permanently

    如果你的循环是循环的,那么只有内部的东西才会被执行

    因此,在循环过程中要调用的所有内容,都放在循环中,或者放在循环中调用的函数中

    例如,如果您只想在特定时间调用showmessageOnthescreen,那么您可能需要在循环中,可能在update方法中使用if

    if (messageNeedsToBeShown())
        showmessageOnthescreen();