Discussion:
Tile Layout Help
(too old to reply)
andrew arthur
2004-06-08 16:05:19 UTC
Permalink
Hi guys,

I'm starting my first Java game, and need some help with the graphics. It's
going to be an RPG on a tile-based 2D map. Here's what I have so far:

About 20 PNG files (50x50) // these will be the tiles
A Tile class which extends JFrame and displays a PNG file
A Map class which creates the map as an int[30][30] array // the value of
the int determines what tile will be displayed

I want the GUI to show only the 400x300 area surrounding the player.

Question 1: Is JFrame the best way to represent a tile?
Question 2: What's the best way to lay out the tiles?

Cheers,

Sean
Nebu Pookins
2004-12-09 19:42:55 UTC
Permalink
Post by andrew arthur
Hi guys,
I'm starting my first Java game, and need some help with the graphics. It's
About 20 PNG files (50x50) // these will be the tiles
A Tile class which extends JFrame and displays a PNG file
A Map class which creates the map as an int[30][30] array // the value of
the int determines what tile will be displayed
I want the GUI to show only the 400x300 area surrounding the player.
Question 1: Is JFrame the best way to represent a tile?
Question 2: What's the best way to lay out the tiles?
Cheers,
Sean
JFrame is probably not the way to go. JFrame adds things like window
borders and so on. Depending on what kind of data you want to associate
with each tile, you might want to either have the Tile class extend
BufferedImage (or some other image class), or just don't have it extend
anything, and just have a reference to an Image as a field in your class.

I'm not sure what you mean by "laying out the tiles". Your Map class
has the basic idea right, but rather than having a 2D array of ints, I'd
just have a 2D array of tiles. You might also want to have a "camera"
object of some sort which takes care of determining what portion of the
map is visible, and translating from tile coordinates to pixel coordinates.

- Nebu

Loading...