Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Snap-to-grid alignment — Gideros Forum

Snap-to-grid alignment

ZizanymanZizanyman Member
edited December 2014 in Code snippets
Here is some code to get objects to snap to a grid (in this case 50 pixels wide) after dragging.

local function round(x)

if x%50 ~= 0 then
if x%50 > 25 then
return math.ceil (x / 50) * 50
else
return math.floor(x / 50) * 50
end
end

return x

end

Then you would call the function in the mouse up function like this:

self:setX(round(self:getX()))
self:setY(round(self:getY()))

Hope this is useful! :)
Sign In or Register to comment.