Looking closer – HTML

The last platform we are going to look at is HTML. This might perplex you even more than iOS did. How on earth do we go from Java to HTML! Luckily, Google has the answer—Google Web Toolkit (GWT). By using GWT will convert Java classes into a JavaScript equivalent.

However, there are some limitations with the HTML export. I would like to add that HTML exports are getting smaller with each release and the smaller releases are the support for certain Java classes. You might find sometimes that there isn't a JavaScript equivalent available and GWT will refuse to compile the code. But having said that, I have used it a lot before and there are always ways around this, and LibGDX has full GWT support from the onset. So as long as you don't stray too far from LibGDX, you will be able to create an HTML game!

Check out the GWT website, http://www.gwtproject.org/, for more information.

Getting ready to launch

Like with the other plaforms, HTML has it's own submodule and a HtmlLauncher class, in which you can see a platform-specific configuration object and the game being created. Very, very simple!

You will notice that there are also *.gwt.xml files here and in the core submodule, these are used so that GWT can find the original source of the code to be translated.

To get the game up-and-running with HTML, on the command line run the following command:

gradlew html:superDev

Once it is run, you will find that it hasn't exited, but instead, it has run its own webserver to provide us the HTML file and JavaScript to us.

Getting ready to launch

Excellent, now if you visit that website in your browser, you will be presented with instructions on how you can enable the dev mode—making debugging easier. Once you have loaded that page, you can go to http://localhost:8080/html/.

The game will then be loaded.

Getting ready to launch

Excellent!

Finally, I want to cover releasing of the game, as you won't want people playing your game in your browser!

Run the following command:

gradlew html:dist

Everything you need to upload on your website will be in the html/build/dist directory. It is as simple as that!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242