snap to grid question ?

Talk about making games.

snap to grid question ?

Postby tinkergnome » Sun Nov 03, 2013 2:08 pm

how could someone code a function to force an object travelling to obey the edit time grid of squares ??

is it possible ?
User avatar
tinkergnome
 
Posts: 16
Joined: Wed Oct 12, 2011 5:11 pm
Score: 1 Give a positive score

Re: snap to grid question ?

Postby DarkParadox » Sun Nov 03, 2013 3:54 pm

You can use a function like this one I made, add it by clicking "Scripts" in the main menu, clicking global code, pasting it in, giving it a title, and adding it.
Code: Select all
int lockToGrid(int val, int delimiter)
{
    return round(val/delimiter)*delimiter;
} // This function will return the nearest multiple of the delimiter to your value.


Use it by going to whatever actor you need to lock down as you say, adding an event with a script editor action and putting in something like this:
Code: Select all
x = lockToGrid(x, 10); // The current actors X value will now round to the nearest 10th pixel.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: snap to grid question ?

Postby tinkergnome » Mon Nov 04, 2013 10:17 am

x = lockToGrid(x, 10); // The current actors X value will now round to the nearest 10th pixel.

^^^ i'm not sure exactly how to express that in a keypress function ... or a mouse button press... hmmm
User avatar
tinkergnome
 
Posts: 16
Joined: Wed Oct 12, 2011 5:11 pm
Score: 1 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest