• 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 Need Help with Isometric Cursor Snapping to Grid

S

Stoneskull

Guest
Hello! I am trying to make an isometric game in GM 1.4.1804 and I need an object to follow the cursor but have it snap to my isometric grid. So far I have my room's grid snap set to 64px by 32px so I can place objects relatively easily but don't have any code built into the objects themselves. My diamond shaped tiles are 64px wide and 32px tall, so I started off by using move_snap(64,32) but that obviously will cause the object to snap between the tiles on their vertices.

I have also tried implementing an offset by figuring out what column the tile is in and adjust the height by 32px downward but this just causes more issues. I've been scratching my head for hours now and I'd really appreciate any help I can get! Thank you all in advance! :)
 
S

Stoneskull

Guest
I wrote one on these too, including very specifically coordinate translation formulas
https://yal.cc/understanding-isometric-grids/
Thank you for all of that! It'll be really useful for me :) Although sadly after reading that and trying to apply the formulas I still can't get any farther than before :/ I can get the tile to snap to a grid just find but it will still snap between the isometric tiles and I can't think of how to get it to only snap on the correct places..
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Thank you for all of that! It'll be really useful for me :) Although sadly after reading that and trying to apply the formulas I still can't get any farther than before :/ I can get the tile to snap to a grid just find but it will still snap between the isometric tiles and I can't think of how to get it to only snap on the correct places..
Convert room coordinates to isometric coordinates, snap those to the nearest cell, convert them back to room coordinates.
 

Curt Lemon

Member
var a, b, c;

a = round(mouse_x / 16) * 16;
b = round(mouse_y / 16) * 16;
c = frac(a / 32);

b += (c * 2) * 8;

draw_sprite_ext(spr_tent_01, 0, a, b, 1, 1, 0, c_white, 0.5);

Here's a script I came up with which seems to snap to grid isometrically for my project. My grid would actually be 32 x 16 pixels.
 
D

Deleted member 102407

Guest
var a, b, c;

a = round(mouse_x / 16) * 16;
b = round(mouse_y / 16) * 16;
c = frac(a / 32);

b += (c * 2) * 8;

draw_sprite_ext(spr_tent_01, 0, a, b, 1, 1, 0, c_white, 0.5);

Here's a script I came up with which seems to snap to grid isometrically for my project. My grid would actually be 32 x 16 pixels.
Thank you, helped me a lot!
 
Top