Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (652)
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  
  graphics 2D -- painting  (Read 1832 times)
0 Members and 1 Guest are viewing this topic.
Offline Noobtastic

Senior Newbie

« Posted 2009-06-08 20:02:27 »

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.

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

Senior Devvie

Medals: 4

« Reply #1 - Posted 2009-06-08 20:17:56 »

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

Senior Newbie

« Reply #2 - Posted 2009-06-08 20:23:33 »

Thanks for the response  Smiley

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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zoto

Senior Devvie

Medals: 4

« Reply #3 - Posted 2009-06-08 20:37:31 »

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

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #4 - Posted 2009-06-09 00:13:38 »

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.

See my work:
OTC Software
Offline Noobtastic

Senior Newbie

« Reply #5 - Posted 2009-06-09 14:54:19 »

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 Smiley
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #6 - Posted 2009-06-12 18:19:56 »

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

Offline Noobtastic

Senior Newbie

« Reply #7 - Posted 2009-06-12 19:10:58 »

Actually, I got this working -- I just never posted the update.  Shame on me  Shocked

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.

I think it's quite an improvement.  Thanks all for help.
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #8 - Posted 2009-06-12 19:31:35 »

Looks great. :-) 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.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

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

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

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

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

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

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

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

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

BurntPizza (25 views)
2015-07-24 06:06:53

NoxInc (32 views)
2015-07-22 22:16: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!