Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  A strategy for designing chess graphics  (Read 3004 times)
0 Members and 1 Guest are viewing this topic.
Offline fguy

Senior Newbie





« Posted 2009-09-21 15:50:36 »

This is my first try to do something meaningful with Graphics2D, previously I have worked only with the Graphics class. It's not so much that I need help, rather I just want to bounce my ideas off the board and see what comes up.

OK, the goal is to improve my chess graphics. The idea is to learn graphics, not just create a better mousetrap. Eventually I want a system where the user can choose beteen piece designs. Some of the designs will be created using the GeneralPath class, others will be from externally created images, such as jpegs.

It seems to me that since I want to switch between both methods of design, then rather than drawing a GeneralPath object directly to the drawing surface, a JPanel, I should proceed as follows...

1. Draw the board directly on to the JPanel. This means the dark and light squares, not the pieces.
2. Create a BufferedImage object, then associate it with a Graphics2D context by using the createGraphics() method.
3. The BufferedImage should have a transparent background, so that a piece can be dragged without obscuring other pieces.
4. Use the usual methods for designing a GeneralPath object, except because of step 2 we are modifying a BufferedImage.
5. When I actually want to visually render the BufferedImage object, I will use a drawImage method on another graphics context which is the chess board. Since we are drawing images to the board and not GeneralPaths, it seems to me there is no need to make the board Graphics2D, plain old Graphics will do.

OK the whole point of going to the extra work of drawing a GeneralPath to a BufferedImage rather than directly to the board is that this will make it easier to switch between using GeneralPath and externally created image files such as jpg for my pieces.

make sense? or am I missing something?

regards.

p.s. OK one question, does it matter what file type I use when my pieces are externallly created images? I suppose jpg is as good as any.


p.s.s. I suppose I can say that if I was only dealing with externally created images, I wouldn't need to use Graphics2D at all.

fchess2 - the rewrite: http://fchess2.blogspot.com/
Offline Wildern

Junior Devvie





« Reply #1 - Posted 2009-09-21 16:20:06 »

For your external images, you will want a format that supports transparency like png or gif.
Offline fguy

Senior Newbie





« Reply #2 - Posted 2009-09-21 16:33:54 »

ok good, didn't know that. Without doing the research, by intuition it seems It would be better if my backgrounds were transparent before the images were loaded into java?

fchess2 - the rewrite: http://fchess2.blogspot.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #3 - Posted 2009-09-21 17:52:49 »

Yeah, if you use ImageIO to create your BufferedImages, they will automatically include transparency as long as your source image had transparency. So just make the PNG as you would want it to look, then load it in.

See my work:
OTC Software
Offline fguy

Senior Newbie





« Reply #4 - Posted 2009-09-23 18:16:54 »

Thanks Demonpants, I ended up using Class.getResourceAsStream, which retrieves the png from the jar file as an InputStream, then used a version of ImageIO.read() that takes an InputStream as a parameter.

Anyways, the results are available on my website if anyone wants to take a look. I included a checkBox in the GUI to toggle between the old and new piece style.

cheers.

fchess2 - the rewrite: http://fchess2.blogspot.com/
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2009-09-23 20:16:44 »

Looks nice, works well. Good job on it. Smiley

See my work:
OTC Software
Offline fguy

Senior Newbie





« Reply #6 - Posted 2009-09-23 21:42:42 »

Thanks. It's worth pointing out that there really is no Graphics2D involved here. All the drawImage() stuff is from the Graphics class. I did use createGraphics() on my blank BufferedImages which creates a Graphics2D context, but then I used basic draw methods for my old style pieces. But what I have done is two set the stage for using advanced primitives and GeneralPath which is Graphics2D. If I ever get around to it. But again as far as i can see you don't need Graphics2D for external images.

fchess2 - the rewrite: http://fchess2.blogspot.com/
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2009-09-23 21:45:19 »

Thanks. It's worth pointing out that there really is no Graphics2D involved here. All the drawImage() stuff is from the Graphics class. I did use createGraphics() on my blank BufferedImages which creates a Graphics2D context, but then I used basic draw methods for my old style pieces. But what I have done is two set the stage for using advanced primitives and GeneralPath which is Graphics2D. If I ever get around to it. But again as far as i can see you don't need Graphics2D for external images.
You're right, but Graphics2D is more powerful and JPanel, etc. actually have a Graphics2D object, not just a Graphics object. So you might as well make the cast to Graphics2D if you want any of the functionality. It won't cost you anything aside from a single cast, which is negligible.

See my work:
OTC Software
Offline fguy

Senior Newbie





« Reply #8 - Posted 2009-10-03 17:47:00 »

For your external images, you will want a format that supports transparency like png or gif.

I have another question. I have access to lots of images, but not so many that have transparent backgrounds. Can you suggest a strategy for modifying an existing image with a solid color background,, usually white so that it has a transparent background? Any good open source or freeware to do the job?, I'm not a big fan of Microsoft Paint, but I'll use it if I have to.

fchess2 - the rewrite: http://fchess2.blogspot.com/
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #9 - Posted 2009-10-03 17:51:40 »

If you want to do it while loading your images it's called 'colour keying', and should be do-able with regular BufferedImage stuff without too much problem.

If you want to do it manually then you could try gimp or paint.net. I prefer Paint.net but it's windows-only, so you might have to go with Gimp.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fguy

Senior Newbie





« Reply #10 - Posted 2009-10-03 18:04:21 »

If you want to do it while loading your images it's called 'colour keying', and should be do-able with regular BufferedImage stuff without too much problem.

If you want to do it manually then you could try gimp or paint.net. I prefer Paint.net but it's windows-only, so you might have to go with Gimp.

OK Thanks, I'll look into color keying and let you know how it goes. It'll be next week sometime before I get around to it.

p.s. For anyone who visits my site to see the images, i had to get rid of them, and go with my primitive shapes. Sort of a personal dispute with the guy who gave me the images. Which is why I am revisiting the issue now.

fchess2 - the rewrite: http://fchess2.blogspot.com/
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.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!