Home > aen's Blog

Tile Selector

Well, that went pretty swift. Build 3, now with Trendy & SlimTM tile selector!

smee, build 3

Here's a look:

I'll not go on and on about everything in minute detail this time around, but have a look in the TileSelector class to see how simple it is. I added an instance to the Main class and then encased both the tile selector and the viewport in a JPanel which became the overall JFrame's content pane.

Then I made a static instance of Main inside itself so I could query it for the tile selector and get the current left & right tiles for plotting while performing plots inside MapPanel. Perhaps not the most elegant solution, but quickly implemented.

You can have a tile assigned to your left and right mouse buttons, like most map editors The current selections for each button are highlighted with fancy programmer boxes!

One item of interest which I don't think people often consider has to do with that fancy tree there. That is a 64x64 tile. There's nothing that says all of my tiles have to be 32x32 just because they're aligned on a grid which is 32x32.

The great thing is if you manipulate the rendering coordinates just a little, you can basically produce overlay-ish behavior without multiple layers. Given the render order, I just match up the lower right edge of the grid cell with the lower right edge of the actual tile I'm displaying.

The end result, with proper placement and a little consideration towards the tile makeup, is a low-tech overlay! There are limits to its usefulness, but it's a nice little extra bang for your buck.

You'll also notice a funky translucent-ish tree as the last tile in the selector. I was futzing around with Gimp and ended up turning on alpha somehow, and decided to keep it. The lower right quadrant of the thing is kinda ganked, but it demonstrates the ability.

PNG supports per-pixel alpha goodness, of course, as does the Java standard library, so it becomes quite easy to include those kinds of tiles.

Enjoy!