1
\$\begingroup\$

I'd like to have a HTML form send data to a LibGDX game deployed as HTML5. Ideally as a form in HTML as part of the same page that contains the LibGDX div/canvas, and use the form to set up some data that I can pass into the game, probably using Javascript.

Is this or any other method of sending data to the LibGDX app (when deployed as HTML5) possible?

\$\endgroup\$
1
\$\begingroup\$

I'm not aware of any reasonably straightforward way to pass form data into an HTML5 LibGDX application on the client side (ie. directly in the browser via HTML and JavaScript only). I would expect any effort to do that would get overcomplicated very quickly since the Java code is compiled down to essentially unreadable JavaScript during the HTML5 build process. There may be something clever that could be done with source maps, but its probably not worth the effort.

This may or may not fit your use case, but if you write a server-side application to handle the form data (in any server-side tech, php, node, java, etc... perhaps storing the form data in a database) then you can communicate with the server-side application from the LibGDX app using the built in networking API of LibGDX such as standard http requests.

A better alternative is probably to just create your HTML forms directly in LibGDX using scene2D UI API and then there's no separation between the input and the game. The downside to this is that if you need to change the forms then you'll have to rebuild and redeploy the game, but if your form data changed significantly enough then you'd probably have to do that anyway in order to process the new data in the game.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.