# Snap/grid building

#### Spannix

##### Member
Hi.im looking for some snapping grid or selection building system like prison architect or rimworld
any idea how to do it or any tutorial ?

#### vdweller

##### Member
First of all, does your game have in place a grid-based map? Like, a grid for the tiles, or another grid with the structures (walls etc)

#### FoxyOfJungle

##### Kazan Games
GML:
``````x = round(x/16)*16;
y = round(y/16)*16;``````
16 = grid size

#### Let's Clone

##### Member
you might want to use 'div' instead of '/' for division. 'div' truncates the result so you know that you're locked into the desired cell of the Grid.

I use ds_Grids in HEAPS of my tutorials. If you're interested in skimming through them, i think it might help. I'm also working on a video explaining Grids and how to use them, if you'd be interested in that.

My channel is: LetsClone

#### TheouAegis

##### Member
x&=~15;
y&=~15;

x = mouse_x & ~15;
y = mouse_y & ~15;

If the grid is a power of 2 (e.g., 2, 4, 8, 16, 32, 64) then you can do this by subtracting 1 from the grid size. ...Bit now we're just talking about various ways to do the same thing. lol

If you don't use a mouse, just move in grid increments to begin with.

#### Spannix

##### Member
yes i have grid and building system, but only for "one line" or one peace of block.
but i need some selector, mark the grids and then build walls/floors

#### Spannix

##### Member
for example i have a grids and some green selector
but i need
when i mark the grids and released button
- create walls and floor on the marked area

#### TheouAegis

##### Member
Same thing. Every time you read the mouse's coordinates, snap them to the grid.

onMouseClick:
x1 = mouse_x & ~15;
y1 = mouse_y & ~15;

onMouseHold:
x2 = mouse_x & ~15;
y2 = mouse_y & ~15;

DrawEvent:
draw_rectangle(x1,y1,x2,y2,0);