graphics 2D -- painting

Hullo,
I am working on a client GUI for a turn-based strategy game. I have a random map generator in place which creates all the map data, which I then render in the GUI. Currently, I have a randomish color picker that plots points out to distinguish the different terrain types. This works ok, but I’m wondering if there might be a way to paint some sort of texture, or use an image as a texture, etc. This screenshot should show what I mean. It shows the current pixel-method. I’m also including a little code that shows how the pixel-method works for one of the terrain types.

http://empireforge.com/images/EFC/pixelGUI.png


	private void drawForestPixel( int x, int y ) {
		
	
		int selector = viewer.main.Main.RAND.nextInt( 10 );
		
			
		switch( selector ) {
			case 0:
				buffer.setColor( DARKER_GREEN );
				break;
			case 1:
				buffer.setColor( TRUNK );
				break;	
			case 2:
				buffer.setColor( LIGHTER_GREEN );
				break;
			default:
				buffer.setColor( FOREST_GREEN );
				break;
				
		}
		
		buffer.drawLine( x, y, x, y );
	}


Sounds like java.awt.TexturePaint is what your looking for.

Thanks for the response :slight_smile:

Looks like that works with Rectangles though, or maybe other shapes. My “sectors” are not shapes, though. Though some of them resemble rectangles, this can’t be guaranteed. Many are completely irregular. I know, for a given sector, all of the points that are in it, however.

Will the texture paint work with that?

It should work if you use the points to create an java.awt.Polygon.

I would just load the texture in as a BufferedImage, then turn the opposite points (the ones you don’t want) transparent. Then the rest will appear like your image. Easy.

Ah, I like that. I was probably going to be unable to create a polygon, as the points I have stored (and the way I’ve stored them) doesn’t lend itself well to defining a Shape.

I will see about using the BufferedImage as described. If I have success, I’ll post a new screenshot :slight_smile:

Learn how the AlphaComposite rules work. You will be able to use texture bitmaps and bitmapped “shapes” as stencils.

Actually, I got this working – I just never posted the update. Shame on me :o

Here is an image with textures instead of random pixel coloring. Note that I did not use the new texture method for the minimap. Seemed unnecessary.

http://empireforge.com/images/EFC/EF_dev_2.jpg

I think it’s quite an improvement. Thanks all for help.

Looks great. :slight_smile: Now you should try to improve the look by having one big grass image that can represent the whole map, then cut out every single non-grass space from it. This will make it look significantly less tiled than it does right now (it still looks pretty unnatural). If this is too expensive for you (in terms of image size), you could just have multiple tile types and then choose them each randomly.

Also, adding some alpha bits to the edges of each tile along an irregular surface could look cool, like the edges bleed into each other. Plus it would look better to make the differences less square.