Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Drawina a hexagonal-tile map  (Read 4299 times)
0 Members and 1 Guest are viewing this topic.
Offline Vicente

Junior Newbie

Java games rock!

« Posted 2003-04-17 09:08:48 »


  I´m doing a Battletech game as part of a university project. The GUI part is more or less done, but I´m stuck in drawing the board. I thought about using a JPanel and rewritting the paintComponent method.

  The board is formed by hexagonal tiles. I have all tiles stored in png files (28x32), and I have read that I need to aply a mask to the tiles to draw them (to take out the parts of the rectangle that aren´t the hexagon). But I´m completely lost on how to do this.

  Any ideas, tutorials,...? Thanks in advance. Greetings,

Offline mill

Junior Devvie

popcorn freak

« Reply #1 - Posted 2003-04-17 09:14:31 »

can't you simply make the images transparent?

Offline cfmdobbie

Senior Devvie

Medals: 1

Who, me?

« Reply #2 - Posted 2003-04-17 09:43:44 »

GameDev have a good set of articles on isometric and hexagonal tile maps.  You might find some useful stuff there:

Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vicente

Junior Newbie

Java games rock!

« Reply #3 - Posted 2003-04-17 10:12:16 »

I´ve been reading gamedev articles. The thing is that I don´t know how to do an image transparent in java.

I create a BufferedImage, get a Graphics2d and draw the png tile in the BufferedImage, but I don´t know how to make the corners transparent when I start drawing all the tiles together.

And when I try to draw the images in the JPanel, if I use a for loop, nothing is drawn, but if I draw them one by one, they appear in the JPanel (and I don´t understand why the for doesn´t work). Greetings,

Offline sma

Junior Devvie

« Reply #4 - Posted 2003-04-17 19:20:39 »

Vincente: Use your favorite graphics tool to create PNG images with 8 bit alpha channel or GIF images with transparent color and Java will do handle them correctly.

Some time ago, I put together a simple hex map demo which might be helpful: The paint method isn't optimal and generates too many Rectangle objects but I'm also using images to draw the hex fields.

.: Truth Until Paradox!
Offline Vicente

Junior Newbie

Java games rock!

« Reply #5 - Posted 2003-04-18 09:37:23 »

Hey sma, thanks a lot for the link. I didn´t know that java handled correctly images with and alpha channel. I´m going to see your demo now. Greetings,

Offline abies

Senior Devvie

« Reply #6 - Posted 2003-04-19 19:05:31 »

You may want to check out my old hexmap code at

At some point in the past this code was able to draw hex maps with quite reasonable speed (including partial updates/refreshes repainting only needed hexes, also handling overdraw for isometric units).  I have updated it last time in 1999, so it could have detoriated since then... Maybe you will find it useful.

Artur Biesiadowski
Offline Vicente

Junior Newbie

Java games rock!

« Reply #7 - Posted 2003-04-20 14:59:34 »

Thanks too abies. I´m learning a lot reading those codes - I´m totally new to java graphics programming, so everything is welcome.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (20 views)
2015-08-04 11:03:17

SHC (38 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (50 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!