Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 1526 times)
0 Members and 1 Guest are viewing this topic.
Offline Noobtastic

Senior Newbie





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

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.



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
   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 );
   }
Offline zoto

Senior Member


Medals: 4



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

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

Senior Newbie





« Reply #2 - Posted 2009-06-08 22: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 Member


Medals: 4



« Reply #3 - Posted 2009-06-08 22: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


Game Engineer


« Reply #4 - Posted 2009-06-09 02: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 16: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




Where's the Kaboom?


« Reply #6 - Posted 2009-06-12 20: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 21: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


Game Engineer


« Reply #8 - Posted 2009-06-12 21: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!