Jump to content
  • Advertisement
Sign in to follow this  
chris_j_pook

Java 2D Tile Game

This topic is 4854 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, Im making a game similar to Zelda using tiles in Java... In my paint loop I have this ... public void paint(Graphics gOld) { if(backBuffer!=null) { Graphics g = backBuffer.getGraphics(); int x = 0; int y = 30; int count = 0; for(int a = 0; a <= NO_OF_TILES; a++) { g.drawImage(tileSprites[tileCode[a]], x, y, null); x+=50; count ++; if(count == 15) { count = 0; x = 0; y+= 43; } } ... Draw player sprite and enemies. ... g.dispose(); gOld.drawImage(backBuffer, 0, 0, null); gOld.dispose(); } } I have an array of BufferedImages (tileSprites) and an array of which tile should be displayed in which position of the screen (tileCode). However this code is running really slow when my character walks around it. The screen is 15x15 tiles big. Any ideas how I can improve performance here ? Cheers Chris

Share this post


Link to post
Share on other sites
Advertisement
Have you tried profiling your code? Are you sure that the performance hit is in the section you describe? The code does not look too bad after all.

One thing you might try is this:

Let's suppose your character walks to the left, so you would have to

1.) move columns 0 to n-1 one column to the right
2.) draw a new first ("zeroth") column at the very left

right?

Instead of redrawing the whole grid, you might try "copying" the image you already have on the screen. Provided of course that copying the image into a buffer and then copying that buffer back onto the screen is faster than your approach.

hth,
Beren

Share this post


Link to post
Share on other sites
This is most likely an issue with how you're dealing with things in Java (http://www.gamedev.net/community/forums/topic.asp?topic_id=324170). You might want to enable the 1.5 OpenGL pipeline for Java2D as this will probably solve your issue right off the bat.

You also might want to look into ditching Java2D completely and going full OpenGL via JOGL or LWJGL. This is just my opinion though.

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!