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…
- Draw the board directly on to the JPanel. This means the dark and light squares, not the pieces.
- Create a BufferedImage object, then associate it with a Graphics2D context by using the createGraphics() method.
- The BufferedImage should have a transparent background, so that a piece can be dragged without obscuring other pieces.
- Use the usual methods for designing a GeneralPath object, except because of step 2 we are modifying a BufferedImage.
- 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.
