Jump to content
  • Advertisement
Sign in to follow this  
chris_j_pook

[java] Tiled java game

This topic is 4732 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 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 [Edited by - chris_j_pook on June 6, 2005 4:03:04 PM]

Share this post


Link to post
Share on other sites
Advertisement
Your problem is probably in the g.drawImage function. One way you can improve on this is to render the screen to a background image, then when the screen moves you draw part of that background image to the screen in a new position. The portion of the screen that is newly visible is the only part you will have to redraw individually.

This only works if your background image is static. If you have flowing water or any other moving image on your background this will not work.

Also, what speed is the computer you're using? In one of my games I do the same thing but in python, which is a bytecode interpretted language. The loop is similar, but runs at about 150 frames per second at 640x480 resolution. I can't imagine how this loop could run slow on your computer when compiled unless there is something drasticly slow in your g.drawImage function.

Share this post


Link to post
Share on other sites
Thanks for the reply,

I have a AMD64 2GHz computer so doubt its that...

Ive edited the code to show exactly what I have got. I am using a backBuffer, is that what you mean ?

If set the number of tiles really low (like 10) the speed improves a lot.

Thanks

Share this post


Link to post
Share on other sites
Have you considered using accelerated rendering if you're not already?

Kev

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!