天天看点

libgdx 编译HTML

Deploy to HTML/JS Eclipse method

Deploying to HTML/JS is straightforward for most cases.

  1. Right click your HTML project and select "Google -> GWT Compile"
  2. Keep the default settings and click compile
  3. A window will appear asking you to select the WAR directory. It is in your HTML project's folder.
  4. GWT will proceed to cross-compile your code into javascript. It will take awhile, but you can view the progress by pulling up the console in Eclipse.

Once the compile is complete everything you need to run your game on the web will be inside the WAR directory. Unless you are using RPC calls or other server side operations in your game, there are only a few things left to do.

  1. Copy the "index.html" file, your assets folder, and the folder ending in "mygdxgame.GWTDefinition" to a directory on your web server
  2. Navigate to the URL and you should see a loading screen for your game

Notes:

  • If you are using server-side operations in your code, you will need to install Tomcat or similar software on your web server and place the full contents of your project's WAR directory in the "webapp" directory. More details here.

Deploy to HTML/JS Other IDEs / Gradle method

In your project root, run the command 

./gradlew html:dist

 (Unix) or 

gradlew.bat html:dist

(Windows) to build.

The result will be placed in the 

html/build/dist

 folder. You can symlink your webroot to this directory, or just copy/paste all the files into your webroot instead.

When running the result, you might encounter errors like 

Couldn't find Type for class ...

. To fix this, please see our wiki page Reflection and include the needed classes/packages.

Make sure you only add classes/packages you really need, because the more packages you include, the slower the build process gets.