0
\$\begingroup\$

I have a chessboard with all the black pieces that move with this code: Code1] I found that when I move the pieces, they will stack on top of each other. How can I prevent this?

I have since changed the code to this: Other Code When I move a piece over another it still picks that piece up, but now it will occasionally completely prevent any stacked pieces from moving. What can I do, and is there a way to do this while still being able to move one piece over top of another?

Also, the pieces origin and collision box ( all similar to the king) look like this: spirte

\$\endgroup\$
0
\$\begingroup\$

Just use the function place_empty:

if(place_empty((mouse_x div 32)*32,(mouse_y div 32)*32)){
    x=(mouse_x div 32)*32;
    y=(mouse_y div 32)*32;
}

In my case, my piece has dimensions 32x32 and its origin is at the top left.

To understand this calculation, I recommend looking at your own question (Way to Round Numbers), the answer of which helps to understand.

If you have difficulties in this, or in converting the code to DnD, just comment.

\$\endgroup\$
  • \$\begingroup\$ I have tried this and updated my question with the results. Can you take another look at it? \$\endgroup\$ – user132400 Dec 8 '19 at 23:02
  • \$\begingroup\$ @K00lman How size is your piece? What is the origin of your piece? \$\endgroup\$ – Boneco Sinforoso Dec 9 '19 at 21:21
  • \$\begingroup\$ The pieces are 64 by 64 and have the center at the corner, outside the collision box if that matters. \$\endgroup\$ – user132400 Dec 10 '19 at 0:45
  • \$\begingroup\$ @K00lman What size grid have you chosen? (gamedev.stackexchange.com/questions/177566/way-to-round-numbers) \$\endgroup\$ – Boneco Sinforoso Dec 10 '19 at 21:15
  • \$\begingroup\$ @K00lman If all pieces have their origin in the same location, I ask you to add an image to the question showing the origin location. \$\endgroup\$ – Boneco Sinforoso Dec 10 '19 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy