Help with grid alignment!

0 favourites
  • 7 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • I'm creating a grid of tiles (the size of the grid and tile can change), and a randomly sized rectangle.

    The rectangle is always some multiplication of the tile size - for example: 3 tiles X 4 tiles etc...

    The rectangle is draggable, and I need it to behave in the following way:

    1. Always stay within the grid boundaries

    2. Move along the grid lines

    - I've sorta managed to do number 1, although there's a very jittery behavior near the edges - if anyone can help with that it would be GREAT!

    - I ripped nearly all my not-so-thick hair trying futilely to get the second behavior to work - no matter what I try, I only manage to get the rectangle to be dragged by tile-sized increments, but it is never aligned with the grid itself... and worse, this misalignment changes as one changes the screen size!

    PLEASE - help me keep what little hair I have left...

    The project file

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey!

    If the size per tile is 20 i would do:

    For height, width, x position, y position divided by 20 * 20.

    Height example: int(sprite.height/20)*20

    Your "TileTop" sprite had the origin in middle, and was created on a weird offset. So no wonder it did not snap on the grid. Either you take that offset into account, or created a grid of "TileTop's" from origin.

    Take a look at this example: gofile.io/d/6yD8iF

    Numpad + = increase width and height by 20

    Numpad - = "you guessed it" decrease width and height by 20

  • For this task it's much easier when origin points are set at [0,0]. Here is the fixed project:

    dropbox.com/s/1e1mg705fx94xp8/align.c3p

  • dop2000 You almost beat me to it :).

  • Thank you both so much :)

    I do need the offset, since the grid is a kind of board game, so having it start at the absolute origin (0,0) is not very practical. However, the offset doesn't have to be 'weird', it can be 100, 150 or something like that.

    I'll have a closer look at what you suggested, and report back if I still can't make it to work.

    Thanks again!

  • I meant the origin points in sprites, not the grid offset.

  • No problem!

    Yea, you don't have to start at origin of course. As long as you take the offset into account.

    And...try to save those hairs, winter is here! :)

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