This has all been very helpful to me. Things I’ve learnt so far have been:
- Do not create anything in the draw routines ie (new Color, new int[10] etc).
- Fewer calls to draw routines the better - a single fillPolygon is much better than multiple smaller polygons.
- Get as much processing out the draw loops as possible - the single call above meant I could build the polygon array elsewhere.
- The standard java sound is useless for gaming. I quite liked TinySound when I tried it.
The end result is my game now runs smoothly on my cheap chromebook (converted to Linux) using only 25% CPU which is better than I expected. The threads I now need for the game are just the main game thread and one to handle IO from the web for high scores etc. I currently don’t need to speed the game up any more but I will look into using BufferedImages or VolatileImages. A few small questions remain though:
How do I change the volume or pan left to right with TinySound?
I currently call pain in my main run loop and record FPS as well as number of moves (of creatures/sea etc) per second (MPS). I limit the MPS to 30 to make the game playable but obviously with
my set up I also get 30 FPS as well. It’s not an issue for me but I was curious how you limit the number of moves but allow the FPS to climb on faster machines?
So far there seems to be lots of ways of calling the program to get it to work. I need the nodraw option otherwise I’m met with a blank screen but others don’t. If the user is on Linux then the java commands need to have a colons rather than semi colons in the path. Should I include a bat file (or many files) to run on Windows and a sh file to run on Linux?
I looked into JavaFX and some of it’s features are neat but perhaps a little complex (30 lines to say hello world!!) but I’ll try to persevere. It’s big advantage to me though is being able to produce an executable so I’ll continue to look into this.
I’ve uploaded the latest version to the web page now.
Mike
PS Has anybody actually played the game?