Dragging/Snapping DEMO
firemaplegames
Member Posts: 3,211
Dragging/Snapping to a Grid
Some people have been asking how to make an Actor snap to a grid, I figured I'd make a little demo showing how it's done.
http://gamesalad.com/game/play/30842
Here is an example of how you would get an actor to snap to a grid while dragging it. This is useful in grid-based puzzle games as well all dragging items into an inventory box, etc.
Fell free to use this in any way you see fit.
Good luck!
Joe
Fire Maple Games
Some people have been asking how to make an Actor snap to a grid, I figured I'd make a little demo showing how it's done.
http://gamesalad.com/game/play/30842
Here is an example of how you would get an actor to snap to a grid while dragging it. This is useful in grid-based puzzle games as well all dragging items into an inventory box, etc.
Fell free to use this in any way you see fit.
Good luck!
Joe
Fire Maple Games
Comments
That's exactly what i needed
I'm just trying to occupy my time while waiting for the Review process. Danger Cats! has been "In Review" since last Wednesday. I guess they have to play every level to make sure there's no secret porno level!
And with the snapping, I had to use the CEIL() function because GS doesn't have a ROUND() function. It would feel a little bit smoother with round()... Because I'm using ceil(), the actor will always snap up and to the right to begin with. Not really a biggie, but there you go.
Yeah, I was thinking: "Rats, I KNEW I should have made level 31 easier..."
You can make it round this way.
N = ceil((floor(N*2))/2)
Or you can round a number by constraining an integer type attribute to that real number value.
If I constrain an integer to the real number, won't that just cleave off the decimal? In essence just a floor?
Just curious, does GS not have a generic rounding function for a reason? I've heard that computers have inherent rounding errors, and even that Macs and Windows round numbers differently.
If it's easy enough to add a round() function to the list of functions in the expression editor, I think that would be a nice addition.
I updated the demo with CodeMonkey's rounding code.
The snapping is now much smoother and behaves as I initially intended.
If you are using the code from the older version, please update your project with the newer version.
Thanks!
Joe