Jump to content
  • Advertisement
  • entries
  • comments
  • views

Compiling java games to javascript

Sign in to follow this  



Ive been very busy with my main project (Legends of Strife) Its pretty much ready for an fully playable release. There is still only one zone but it has about 60 quests and 20 spells/abilities and a decent amount of frendly and hostile npc's with unique behavior and lots of items/stats and a working "town siege" system but il save that for another post in the hopefully near future.

I decided to take a little break from that so for the last three weeks I've been playing with a library called TeaVM. It allows java classes to be converted into javascript to run directly in the browser. As far as I understand there are other projects that aim to do the same but before now I never thought it possible ^^. So I took the time to create a javascript implementation of my engines "system interface". basically swapping openGL calls for webGL and instead of loading files from disk downloading them through the browser etc.

I then went ahead and compiled one of the smaller games i made a few years ago and it works very well. For me this is amazing. I used to have a website hosting of couple of games that i created in java + opengl using my engine. But they all ran as java applets wich is basicly blocked everywhere now. Chrome fully blocks java applets regardless of security setting as of about two months ago and other browsers make it so hard it might as well be fully blocked. But even when java applets were still feasible they were annoying since the users had to have java (and a new enough version of java) installed. It also even back then came up with threatening security warnings that detered users and anyone with slightly higher than "normal" security settings could not run it. Making sure the applet ran in linux or mac also needed quite a bit of effort.

Now i can host those games again and have them run in the browser with no security warnings, no plugins and less cross platform issues (Only tested it on windows and linux using chrome though).No changes were needed to the actual game to have it run in the browser. So the exact same game code runs as a desktop app as well as in the browser.

There is one big downside though. It is quite a bit slower. But since its small games thats hardware rendered it doesnt matter too much. And i expect it to only get better with time.

One other drawback is that TeaVM doesnt support reflection. and probably never will based on the fact that it only compiles methods that can possibly execute though static linking. Wich once again for smaller scale projects should be no problem. I had to do a little refactoring on my engine to get rid of one or 2 instances of reflection but that wasnt too much of a problem. On the other hand this makes compiling really fast and the output javascript as small as possible.

Lastly I found that TeaVM failed to compile some deeply nested loop structures with labelled break or continue statements so I had to do a little more reworking in that regard. But i hope future versions will address that. Its only at version 0.4.0 and seems to be under active development.

I hosted the game here. http://www.distantmelody.net/spheres-of-madness/

I plan on soon putting up my other small games as well biggrin.png

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!