0

My goal is to make checkers game , where user can move checkers on the board.

The board I have made is from DataGridView class .

Right now what am i doing is creating picture boxes for each checker with transparent background and when the user moves the selected checker i am setting him BringToFront.

The problem is that the "transparent" effect is actually relative to parent control, and the parent of all checkers is the DataGridView.

So the result is when there is 2 checkers overlapping there is no transparent effect .

Example of my problem image

I have got some solution but its takes a lot of memory and all freezes even on thread which is not in UI thread.

My solution was to have one big panel (parent of all checkers) that its background is build of client screenshot and changes while moving the checker.

What is the correct way of doing thing like that ? I was looking and trying solutions on the net from the mooring ): Please help !

Edit :

Almost done :

https://youtu.be/nyhfIOzqeY8

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Stav Bodik
  • 2,018
  • 3
  • 18
  • 25
  • you should really be drawing everything on _a single_ picturebox –  Jun 08 '16 at 23:41
  • Ok so i took screen shoot after loading the board and checkers and then i make all checkers parent to be the panel which is holidng this screen shoot : http://s33.postimg.org/57e2f6r4f/image.png – Stav Bodik Jun 09 '16 at 00:07
  • I mean you should draw every checker piece directly to one single picturebox, and use the method here: http://stackoverflow.com/questions/4779027/changing-the-opacity-of-a-bitmap-image, to achieve transparency. MUCH faster than creating controls –  Jun 09 '16 at 00:14
  • SetImageOpacity will change the opacity of all image , yes each checker is already inside single picturebox . – Stav Bodik Jun 09 '16 at 00:20
  • no I mean _everything_ inside _one_ picturebox not separate boxes for each; if you want to optimize your program then this is not the way to go –  Jun 09 '16 at 00:22
  • Almost done https://youtu.be/nyhfIOzqeY8 – Stav Bodik Jun 09 '16 at 00:46

2 Answers2

0

If you are going to use pictures I wouldn't use transparency. Transparency is slower in every application.

Let's think for a minute about an alternate solution. How many states can a square be? Primary colored square can be empty, or have a red or black piece on top. The alternate colored square never has a piece on it.

That is a total of 4 states. So 4 images which can be separate or combined on a spritesheet. Then you just need to switch the picture depending on its state. Primary empty, primary with red, primary with black, or alternate colored square.

If you want a fancy border you can use an image for that behind or beside if you build it piece by piece.

R. Dmytruk
  • 96
  • 4
0

So if anyone in the future will need help with this issue .

The idea is to have another control panel over all the other panels (game board and checkers).

Then each time we would like to move an checker we take a screenshot from the game board without the moving checker and putting this screenshot to be the image of the top most panel.

Now we change the parent of the moving checker to be the top most panel and now we are moving the checker upon this panel with transparent background.

https://youtu.be/PUEyZPhPTlc

(:

Stav Bodik
  • 2,018
  • 3
  • 18
  • 25