I know there are few old topics on the forum about grid, but they are old and have old project examples format (gdg). I’ve tried few things from those topics, but I can’t handle…
I just want to make most simple puzzle game. For now I have pieces on one part of the screen and board for which I can put on the puzzles. The rest of screen has collider which makes the pieces back to their original position when I drop them there. It’s fine, but I the thing is, my puzzles has no grid and I can put them on board chaotic, while I need them to be snapped in order
Any ideas how to do this in some simple way?
You could do your grid as pieces put together instead of a background image
each grid piece a Sprite then when you release the puzzle piece check if it is over a grid piece and if it is center it.
yes, I thought about something like that But could you tell me which events and actions use to achieve that effect? I’m not good in variables and numbers
i guess your objects have draggable behavior. You have is dragging event, I don’t have a computer at the moment bit look for this event, then you need a variable to know which object is being dragged. When you release mouse get X and Y coordinates of mouse.
Is a bit trickky, i started the code but left incomplete before finishing.
I can get the snapping working by placing sprite objects on my canvas then the draggable objects have conditions like "when not being dragged & collide with ‘placeholder object’ " then “put an object around another”.
This makes them snap perfectly, however, I also wanted to make it so two pieces could not snap at the same time but I’m having trouble making it do that.
No problem. I decided to move away from full snapping and only allow snapping to the correct placeholder, otherwise I use tween to make the object bounce back to the original location.
I’m making a simple word puzzle so this works for me.
If they have, I set variable Arrastrando (dragging) to 1,If you release and press button again notice that I set the variable to 0 each time you do a click. Here I thought I could use internal variables for object or scene variables to store the original position of the object being dragged in case you release it on a place where it should.
The next event to check is mouse button released, when you release button it means you stopped dragging, so I get MouseX and MouseY coordinates and check if they are where I wanted the object to be dragged.
There is a lot more to do but it is a beggining, hope this helps
The draggable behavior works fine - until you have a hit box that is not a rectangle and the non-hit box area overlaps another shape (see: Click and Drag with overlapping objects). I ended up creating my own function to ensure that the object clicked is the object that is dragged. If you are interested, I can share the function later tonight (right now I am on an Amtrak and the internet connection stinks). I have another function that snaps to a grid but only when the dragged piece is entirely inside the “play area”.