How do I make something, spawned at the cursor, on a grid?

0 favourites
  • 5 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • So, I'm making a sandbox game. I want the player to be able to place objects where their cursor is, but i still want it on the 128x128 grid. I can't find a way to do this, I don't see a way to make something spawn on the cursor, but on an offset. Any suggestions?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • On clicked, store Mouse.X and Mouse.Y

    Use math to split the position with grid size so you will be able to know the grid position to place the object.

    Example: Mouse.X=1222 and Mouse.Y=342

    The grid size is 128x128 so

    1222/128 = 9.54

    342/128 = 2.67

    So you need to create the object on grid 9x2..

    Converting into pixels.. 1152x256

  • On clicked, store Mouse.X and Mouse.Y

    Use math to split the position with grid size so you will be able to know the grid position to place the object.

    Example: Mouse.X=1222 and Mouse.Y=342

    The grid size is 128x128 so

    1222/128 = 9.54

    342/128 = 2.67

    So you need to create the object on grid 9x2..

    Converting into pixels.. 1152x256

    I am very late, but I tried this from what I could understand. I got this. imgur.com/7gmtUit. But, it doesn't work, and just places it far away from the mouse (on no grid).

  • > On clicked, store Mouse.X and Mouse.Y

    > Use math to split the position with grid size so you will be able to know the grid position to place the object.

    >

    > Example: Mouse.X=1222 and Mouse.Y=342

    > The grid size is 128x128 so

    > 1222/128 = 9.54

    > 342/128 = 2.67

    >

    > So you need to create the object on grid 9x2..

    > Converting into pixels.. 1152x256

    I am very late, but I tried this from what I could understand. I got this. imgur.com/7gmtUit. But, it doesn't work, and just places it far away from the mouse (on no grid).

    On clicked -> Create Object At

    X: (floor(Mouse.X/16))*16

    Y: (floor(Mouse.Y/16))*16

    Dont forget to set the sprite origin image point at Top Left

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)