Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

♥ FREE Snap To Grid tutorial/template - some community love ♥

LumpAppsLumpApps Posts: 2,867Member
For the love of this community! An easy snap to grid tutorial and attached template

Snap to grid: THE MATH
- Take the X position of the actor and divide it by the grid size. The answer is the place on the X axis in the grid.
For example: the grid = 64px wide. Then an actor on self.position.X = 128 will be on place 2.
- The outcome needs to be floored (rounded down)
For example: the grid = 64px wide and the actors self.position.X = 133 the place on the grid will be 133 / 64 = 2.078125 floor(2.078125) = 2!
- To determine the position on the grid the place we found needs to be multiplied by the width of the grid.
Example: 2 x 64px =128px
- But since the actors X is in the centre of the actor and not on the (bottom-)left we need to add half of the grid width to the outcome
Example: 2 x 64px = 128px + 32px = 160px
- The actors size can be bigger or smaller then the grid size.
- Its the same for the Y position but off course the width of the grid and actor should be exchanged by height.

Put these two change attributes in the beginning of your actors and you will have a snap to grid behaviour.
self.Position.X = (floor( self.Position.X /64)*64)+32
self.Position.Y=(floor( self.Position.Y /64)*64)+32

Projectfile is attached to play with.

With love from Lump ;)


Sign In or Register to comment.