• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Object move_snap and creating instances

V

Vanthex

Guest
Hi guys,
I created a step event for my object obj_selection that first it jumps to mouse_x and mouse_y, then I used code using move_snap for it so that it only goes to coordinates that are a multiple of 32. here is the code for move_snap:
Code:
move_snap(32, 32);
However sometimes it doesn't always follow the mouse and it's very glitchy. Any suggestions?
obj_selection has depth -1, obj_tile has depth 0
Also, I have a right button event for another object obj_tile where it creates an instance using obj_selection's coordinates and with no animation and image_index is 4. But when I right click nothing happens, same with right button released and pressed. Here is the code for that:
Code:
with (instance_create(obj_selection.x,obj_selection.y,obj_tile)) {image_speed = 0;image_index = 4}
I tried places where there are no obj_tile instances so it doesn't overlap, still nothing happens
 

Jakylgamer

Member
if youre trying to snap an object to the mouse something like this will work
Code:
x = round(mouse_x / 32) * 32;
y = round(mouse_y / 32) * 32;

if mouse_check_button_pressed(mb_left)
{
    if  !position_meeting(x,y,obj_block)
    {instance_create(x,y,obj_block);}
    else
    {show_message("a block is there!");}//debug testing
}
 
Top