How to use the "snap to grid" function during the game?

0 favourites
  • 4 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hello

    I'm making a space buldier game and I'd like to do a similar function as snap to grid but during in game!

    For exemple I'll select a station and I want to build it. This can only build places specified in the space.

    Such as snap to grid function in the game editor!

    Is there some simple solution? For exemple something event settings or other else...

    I hope you understand what I want

  • Make 2 variables for the amount of pixels in each incrememnt you want objects to snap to named snapX and snapY.

    Then when you are placing the object, set it to Self.X - (Self.X % snapX) and Self.Y - (Self.Y % snapY)

    The % operator is called modulo, modulus, mod, etc. It gets the reainder after a division. So youre subtracting the amount of pixels the object is between 2 snap points, and setting it to the lower one.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Following on from EncryptedCow, if you are using the mouse to then:

    Set X position to : Mouse.X - Mouse.X % gridSize

    Set Y position to : Mouse.Y - Mouse.Y % gridSize

    where gridsize is whatever you want.

  • Thanks! Your solutions is worked!

    ------

    Global number: snapY = 22

    Global number: snapY = 20

    Set position to + Create object:

    Mouse.X - (Mouse.X%snapX)

    Mouse.Y - (Mouse.Y%snapY)

    Thanks!

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