Snapping objects/ buttons to locations
Posted: Sun Apr 10, 2016 6:25 pm
So my IT course requires that we design and create a simple game. I decided to make a mini Professor Layton type of puzzle game. The first puzzle is one of the "rearrange the matches to make a different shape" ones, and I'm having some problems.
I have a set up with a bunch of buttons with an image of a matchstick set as the icon. I can make these move with
But the problem I have is with the MouseUp code.
I tried this at first:
Followed by else if's for the other grid lines.
"Grid V1" refers to a bunch of equal sized lines I made and arranged like a grid. The idea is that you can snap the matches to the grid lines, and they will automatically rotate to fit onto that section of the grid.
But obviously that isn't the correct way to phrase that. I googled around and found something that kind of works, but it doesn't work all the time:
I don't really know what that means, and I think the "left" bit is wrong for me.
Is there some way I can get the matches to snap to the grid and rotate to be the same rotation as the grid line? Thank you
I have a set up with a bunch of buttons with an image of a matchstick set as the icon. I can make these move with
Code: Select all
on mouseDown
Grab me
end mouseDown
I tried this at first:
Code: Select all
on mouseUp
if the loc of me is <20 graphic "Grid V1" then
set the loc of me to loc of graphic "grid v1"
"Grid V1" refers to a bunch of equal sized lines I made and arranged like a grid. The idea is that you can snap the matches to the grid lines, and they will automatically rotate to fit onto that section of the grid.
But obviously that isn't the correct way to phrase that. I googled around and found something that kind of works, but it doesn't work all the time:
Code: Select all
on mouseUp
if abs(item 1 of the loc of me - the left of graphic "Grid V1") < 20 then
set the loc of me to loc of graphic "grid v1"
Is there some way I can get the matches to snap to the grid and rotate to be the same rotation as the grid line? Thank you
