Legacy GM How to create instance snap to grid

V

VansiusProductions

Guest
Hi guys
How to create an instance that align's to a 32x32 grid according to mouse_x and mouse_y using gml?
 
T

the_great_evil100

Guest
instance_create((floor(mouse_x / 32) * 32),(floor(mouse_y / 32) * 32),object_index);
 
V

VansiusProductions

Guest
instance_create((floor(mouse_x / 32) * 32),(floor(mouse_y / 32) * 32),object_index);
Doesn't work. I have instances that are going to be selected (called element) that have 0,0 as origin for their sprite and are 70x70 pixels in size
My selection sprite is 70x70 pixels in size and has center origin (35,35)
 

TheouAegis

Member
Technically it's

instance_create(mouse_x & ~31, mouse_y & ~31, object_to_create)

If you don't like where that puts the newly created object, modify the code like so:

instance_create( (mouse_x & ~31) + XX, (mouse_y & ~31) + YY, object_to_create)

where XX and YY are the offsets to position the instance properly.
 
Top