Jump to content
  • Advertisement
Sign in to follow this  
Lobodus

[java] Java applet game questions

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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.

Cheers
/Lobodus

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
If you want to make things move at the same rate on all computers, you can just multiply the distance moved by the time since last update

Share this post


Link to post
Share on other sites
Hi,

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,

Nouk²

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!