0

Basicly, I want to make a game of chess.

The idea is that I have a picture of a chessboard and the individual chess pieces. What I could get to work is a JPanel where I would repaint everything everytime with the new positions of the chess pieces, but this would require to get the positions of all chess pieces and repaint the board with up to 33 pictures, with double buffering and all.

A bit resource consuming I think. AFAIK, there is the option to only repaint a certain area, but I guess there're still better ways. What I could imagine is, just moving or removing one or two pictures or rather chess pieces each time rather than repainting something.

I sadly have only very limited knowledge of the classes out there and so I ask if there is such a way or even an entirely different one, that does the job more efficient than painting/repainting.

KF2
  • 9,887
  • 8
  • 44
  • 77
  • 1
    See also this [example](http://stackoverflow.com/a/2562685/230513) and [variation](http://stackoverflow.com/a/2563350/230513). – trashgod Apr 05 '13 at 08:03

1 Answers1

2

Instead of inventing the wheel again, use a game engine with sprite support like JGame to do the rendering.

Also note that today, the resource consumption to render chess is so small that spending a minute to optimize it is a minute wasted. What you should aim for is a framework which takes the least time to implement the rendering of the game so you don't have to spend too much time on this part of the game.

If you feel a game engine to be overkill, how about using a table with a custom cell renderer which draws each cell? The table will make sure that updates are rendered in an optimal way. You might even be able to use a custom TableModel to define the playing field.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Well, while it isn't a homework, it's a case of "choose yourself a project and you get a note for it", so I doubt I'm allowed to use any non native Framework. Of course the teacher isn't available that easy, because, that would make it easy for me. The table idea is really interesting, I'm gonna look into that. – user2247969 Apr 05 '13 at 07:48