【问题标题】:Is it possible to compile a LibGDX game for HTML if it uses Socket.IO? If so, how?如果使用 Socket.IO,是否可以为 HTML 编译 LibGDX 游戏?如果是这样,怎么做?
【发布时间】:2020-03-25 23:48:51
【问题描述】:

来自what I've seen,它似乎在我的游戏中使用了socket.io并让它运行,我需要做很多工作来为Java和其他目前不属于我专业领域的东西包装JS代码。

我应该尝试学习并执行这个建议的解决方案吗?它应该默认工作而我只是没有做对吗?有没有 Socket.IO 的替代方案,我可以使用和实现而无需更改太多代码库?


如果您想要更具体的问题,在任务“draftCompileGwt”期间会发生以下错误:

> Task :html:draftCompileGwt
Loading inherited module 'com.lab.guy.GdxDefinitionSuperdev'
  Loading inherited module 'io.socket'
   [ERROR] Unable to find 'io/socket.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?

当我将此代码添加到 GdxDefinitionSuperdev.gwt 时:

<inherits name='io.socket' />

如果我不这样做,错误是:

> Task :html:draftCompileGwt
Compiling module com.lab.guy.GdxDefinitionSuperdev
   [ERROR] Errors in 'file:/C:/Users/Gui/Desktop/Projects/Games/TouhouIO/core/src/com/lab/guy/Touhou.java'
      [ERROR] Line 53: No source code is available for type io.socket.client.Socket; did you forget to inherit a required module?
      [ERROR] Line 177: No source code is available for type io.socket.client.IO; did you forget to inherit a required module?
      [ERROR] Line 188: No source code is available for type org.json.JSONObject; did you forget to inherit a required module?
      [ERROR] Line 204: No source code is available for type org.json.JSONException; did you forget to inherit a required module?
      [ERROR] Line 212: No source code is available for type io.socket.emitter.Emitter.Listener; did you forget to inherit a required module?
      [ERROR] Line 409: No source code is available for type org.json.JSONArray; did you forget to inherit a required module?
   Tracing compile failure path for type 'com.lab.guy.Touhou'
      [ERROR] Errors in 'file:/C:/Users/Gui/Desktop/Projects/Games/TouhouIO/core/src/com/lab/guy/Touhou.java'
         [ERROR] Line 188: No source code is available for type org.json.JSONObject; did you forget to inherit a required module?
         [ERROR] Line 204: No source code is available for type org.json.JSONException; did you forget to inherit a required module?
         [ERROR] Line 53: No source code is available for type io.socket.client.Socket; did you forget to inherit a required module?
         [ERROR] Line 177: No source code is available for type io.socket.client.IO; did you forget to inherit a required module?
         [ERROR] Line 212: No source code is available for type io.socket.emitter.Emitter.Listener; did you forget to inherit a required module?
         [ERROR] Line 409: No source code is available for type org.json.JSONArray; did you forget to inherit a required module?
      [ERROR] Errors in 'file:/C:/Users/Gui/Desktop/Projects/Games/TouhouIO/core/src/com/lab/guy/Player.java'
         [ERROR] com.lab.guy.Touhou cannot be resolved to a type

带有堆栈跟踪的完整日志:https://pastebin.com/uT1pH0PV

P.S.: 为桌面编译时,正确包含了 Socket.IO。它出现在我的 build.gradle 的“核心”部分。我正在运行的服务器在 Node.JS 中。

PPS:如果我能看到如何使用 Socket.IO 使基本的 LibGDX 应用程序(baglogic 徽标)编译为 HTML,我可以用它代替我的代码并让它工作:)

感谢您的阅读!

【问题讨论】:

    标签: javascript java gwt socket.io libgdx


    【解决方案1】:

    使用 GWT,仅包含一个 javascript 库并从 java 代码中引用它是不够的——您需要为 javascript API 定义一个 java 包装器,以便您可以从您的 java 代码中访问它。

    例如,有一个项目https://github.com/jumanor/gwt_socket.io,其中有人在 GWT 中为 socket.io 创建了一个 java 包装器。

    一旦构建,应用程序需要由 HTTP Web 服务器提供服务,例如 apache 或 node.js 模块 serve。然后,您可以将浏览器指向正在提供的 URL 并在浏览器中运行它。

    【讨论】:

    • 我尝试使用 GWT Socket.IO,但在尝试运行本机方法时遇到了问题:java.lang.UnsatisfiedLinkError。如何让 JNI 去寻找 JS 代码?
    • 该错误听起来像是您在 JVM(例如 node.js)中运行它。它必须在网络浏览器中运行。
    猜你喜欢
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2011-09-03
    • 2023-04-10
    • 2015-11-02
    • 2012-04-08
    • 2021-06-30
    相关资源
    最近更新 更多