Sign in to follow this  

[java] Java applet game questions

Recommended Posts

Hi! I am new to Java applets and am making my first Java applet game. It's a simple plattform game where the player is collecting small floppy discs and avoiding getting hit by angry robots. The game is nearly finished and is working fine, but I have some questions that I'm not able to find the answear to myself. I hope someone here can answear. You are my only hope. :) 1. For some reason all graphics are flickering the first time is it shown. This does not look nice. An ugly solution would be to draw all images quickly to the screen before the game has started, but I feel there is a better solution. I am using normal java.awt.image Images. All game objects are storing their own Images. Maybe there are some way I can buffer all the images before they are drawn? Or am I just missing something? 2. There is a couple of different levels in the game. The levels are tile based and consists of small 17x17 sized pictures which are drawn to the screen. The level pieces are not moving so it feels like a waste of computer power to draw each level more than once. Right now all the tiles are drawn to the screen every time the paint() method is called. I have a method called "makeBg" which are drawing small rectangles to a Graphics (Java.awt.Graphics) with a couple of backgroundGraphics.fillRectangle-calls making a nice shaded background in optional colour. Then I am, instead of drawing 20 filled rectangles to the screen every time paint() is called, just drawing the backgroundGraphics. An idea is to make the "makeBg" also draw all the level elements (walls etc.). It would make the program do fewer painting operations. For some reason backgroundGraphics.drawImage does not seam to work at all from the makeBG-method. Neither does it work very well to draw the Images just one time from paint(). Sometimes all the Images are drawn, sometimes just the half of them and sometimes none of them are drawn. I don't understand why it is behaving like this. Is there a solution to this or do I have to draw all the images every time? 3. My game is running faster on a faster computer and slower on a slower one. This is becourse the game just consists of a loop where I use a tread.sleep() to adjust the speed. How can I make the speed constant? Should I check how many milliseconds that have passed since last move? Thanks a lot in advance! / Lobodus

Share this post

Link to post
Share on other sites
Tada! I solved the image-problems (the two first problems).
It was rather easy actually. I did not know about the
MediaTracker-class, but that one fixed it all.


Share this post

Link to post
Share on other sites
Hi, for the speed problem it looks like time based movement may help keep things consistant, the only down side is that it can be complex to implement and may lead to stuttering/jerkiness on slower computers.

On my java platform games, i just locked things to a fixed rate. That way, at least it did not run too fast on faster computers!

Btw, how come your image size is 17x17 and not 16x16? normally multiples of 8 are faster due to alignment.

Share this post

Link to post
Share on other sites

You should have a look at a dedicated framework for 'flash like' applets: pulpcore under LGPL license.

It handles most of the stuff you usually need when developping games embedded in applets:
- can run with JRE 1.4 without any other dependency.
- no 'security popup' displayed.
- multi browser compatibility
- customized loading screen (instead of the ugly 'Java' stuff)
- sprite / dirty rectangles management
- blending (add, mult, SrcOver, ...)
- sound, animation support
- avoid timing issues (allows 'global time dependend' animations).
- GUI widgets (textboxes, sliders, buttons, ...)
- (really) good performances
- and lot's of other things.

I already developped a multiplayer game with it and I'm currently implementing a 2D isometric engine for this framework.

Best regards,


Share this post

Link to post
Share on other sites

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

Sign in to follow this