简体   繁体   English

使用带有libgdx和GWT的第三方库

[英]Using a third-party library with libgdx and GWT

As I'm sure many others have, I've written my own game engine and am successfully using it with libgdx in my desktop project. 我确信很多人都有,我已经编写了自己的游戏引擎,并且在我的桌面项目中成功地将它与libgdx一起使用。

Now, it's time for me to get the HTML5 project working. 现在,我应该让HTML5项目正常运行了。 I followed these directions to integrate my game engine, the "third-party library", into the HTML5 project. 我按照这些指示将我的游戏引擎“第三方库”集成到HTML5项目中。 However, it hasn't gone smoothly. 但是,它并不顺利。 When I do GWT Compile, I get the following: 当我做GWT编译时,我得到以下内容:

[ERROR] Errors in 'file:/C:/Data/Development/Java/mygame/src/com/me/mygame/MyGameFoo.java'
[ERROR] Line 1329: The method bar(EngineObject) in the type Foo is not applicable for the arguments (GameObjectA)
[ERROR] Line 1333: The method bar(EngineObject) in the type Foo is not applicable for the arguments (GameObjectB)
[ERROR] Line 1340: The method bar(EngineObject) in the type Foo is not applicable for the arguments (GameObjectB)
[ERROR] Errors in 'file:/C:/Data/Development/Java/mygame/src/com/me/mygame/MyGameBar.java'
[ERROR] Line 3: The import com.me.engine cannot be resolved
[ERROR] Line 7: EngineObject cannot be resolved to a type
(and so on...)

Both GameObjectA and GameObjectB extend EngineObject, so obviously I'm quite confused by this output. GameObjectA和GameObjectB都扩展了EngineObject,所以很明显我对这个输出很困惑。

Foo is a class in the engine, so the bottom two errors don't make any sense either. Foo是引擎中的一个类,所以底部的两个错误也没有任何意义。 How can it find com.me.engine.Foo.bar(EngineObject) in the first few errors but not be able to find com.me.engine in the last two errors? 如何在前几个错误中找到com.me.engine.Foo.bar(EngineObject)但在最后两个错误中找不到com.me.engine? (And remember, this all works in the desktop project!) (请记住,这一切都适用于桌面项目!)

The only conclusion I can make is that my project setup or GwtDefinition.gwt.xml is incorrect. 我可以做的唯一结论是我的项目设置或GwtDefinition.gwt.xml不正确。 I'm stumped as to where I've gone wrong though- any advice is greatly appreciated. 我很难过,虽然我出错了 - 任何建议都非常感谢。

GwtDefinition.gwt.xml: GwtDefinition.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
<module>
    <inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
    <inherits name='com.badlogic.gdx.controllers' />
    <inherits name='com.badlogic.gdx.controllers.controllers-gwt' />
    <inherits name='Engine' />
    <inherits name='MyGame' />
    <entry-point class='com.me.mygame.client.GwtLauncher' />
    <set-configuration-property name="gdx.assetpath" value="../mygame-desktop/resources" />
</module>

I thought the "inherits name='Engine'" line was all I needed? 我认为“继承名称='引擎'”线是我需要的全部? Without it, I get a bunch of "No source code is available" errors, so I know I'm doing something right. 没有它,我得到一堆“没有源代码可用”的错误,所以我知道我做的正确。 (It also proves that it's finding the Engine's source!) (它也证明它正在寻找引擎的来源!)

(Using JRE7) (使用JRE7)

Add src element to your module gwt.xml 将src元素添加到模块gwt.xml中

< source path="your-translatable-code-path" />

More info here -> DevGuidemodule 更多信息 - > DevGuidemodule

also make sure that your module is also packaged as source, along with compiled jar file, and both are available on the classpath. 还要确保您的模块也与源代码一起打包,以及编译的jar文件,并且这两个模块都可以在类路径中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM