[gameprogrammer] Re: Java Advice - 2D RTS Graphics

Fantastic, Stephen! Thanks very much! :)

I'll try that out and let you know what happens... :)
-Mike

----- Original Message ----- From: "Stephen" <gp@xxxxxxxxxxxxxxxxxxxxxxxx>
To: <gameprogrammer@xxxxxxxxxxxxx>
Sent: Sunday, October 23, 2005 8:29 AM
Subject: [gameprogrammer] Re: Java Advice - 2D RTS Graphics



To give you the gist on BufferStrategy, you just use it like this (though I'm by no means the world expert on this):-

public class MyGameWindow extends JFrame {

   public MyGameWindow() {
      this.setVisible(true);
      // Set it up here
      this.createBufferStrategy();
      BS = this.getBufferStrategy();
   }

public void gameLoop() {
while (game_not_crashed) {
Graphics g = BS.getDrawGraphics();
g.drawImage(background_image, 0, 0);
// loop through your on-screen units here, drawing them and their health bars.
BS.show();
// Thats ll there is to it. Note there's now no paint(g) function!
}
}


}

Re-drawing the whole map each time is a massive drain on resources. What I do is either have one large image for the background (that's hardly ever going to change) that can be drawn in one swoop, or have a tiled background, which is quick to draw and you only need to draw the visible area each frame. I then draw all the on-screen units seperately each frame, as chances are their position will have changed since the last frame.

Cheers,

Stephen


Mike Gillissie wrote:

Hey, Stephen! :)

I've written an RTS using Java (http://www.carlylesmith.karoo.net/simwar/) and I only used the standard AWT/Swing stuff and never had any performance problems with the graphics; I think it all comes down to how you implement it. Are you using the BufferStrategy? I assume you're not re-drawing the whole image each time, only whats changed since the last frame.


I'm not actually using the BufferStrategy - I'll have to do a bit of reading up on it, I can see... ;)

Because my background map is currently a single continuous image, I am currently redrawing the entire thing, then overlaying the VISIBLE units - I'm not sure how to move a unit from one position to the next without redrawing the background iamge, which overwrites the non-moving units as well as the moved units... I wonder if I should read in my map as separate "tiles" and redraw only the ones that need refreshing... food for thought... ;)

Thanks for linking me to your game! I'll try it right now, and see how you did it - this is a great help! :)
-Mike




---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html











--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html






--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: