♥ FREE Snap To Grid tutorial/template - some community love ♥
LumpApps
Member Posts: 2,881
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
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
Comments
Lump Apps and My Assets
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Lump Apps and My Assets
Lump Apps and My Assets
Highly generous for a single community member , but it doesn't make up for no community love week :-S
Chakku
Lump Apps and My Assets
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
Lump Apps and My Assets
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Lump Apps and My Assets
This is great! Thank you! Not sure if you are still on this thread or not... but I am working with a game that has a similar function to it, but the execution is being odd. I want to be able to tap, move to a place on the grid and then place the item with one click/tap. On the computer previewer (PC) it works fine. But on the Android GameSalad previewer app, I have to double tap to place the item on the grid. This slows down the play of the game and my husband (playtesting) says it is annoying enough that he would delete the game, even though the rest is fun. Any ideas on what could be causing this? Is there a post somewhere that explains it? I jumped on here because the touch/mouse/press/etc is all that is missing from the original post. Thanks!
Hi @jlrobertson1993 Thanks for your reply. It has been a while since I used GameSalad so don't think I'm of much help. Maybe some of the other veterans can jump in
Lump Apps and My Assets
@jlrobertson1993 You might want to start a new thread for this conversation but I'm wondering... are you wanting the user to tap and drag and then release? If so, I have a few demos of this I can post.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang I have been wanting to post a new thread, but I am worried that I won't be able to explain the background of how the game is built currently enough to get an answer, which is why I jumped on here, as others seemed to already know the basic foundation without me muddling an explanation. But, yes, tap/drag/release is what I am after! :-) Thank you!!!
@LumpApps Thank you!! :-)
@jlrobertson1993 Are any of these demos helpful?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang I will check them out! Thank you!!!!