Grid Question

0 favourites
  • 7 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hello Again Dear Community :)

    So yes, I am here again with a quick question;

    I used to goof around with Construct Classic and making some kind of Terraria / Minecraft 2D clone (for own entertainment, not for sharing really) And I thought I'd make a newer version in Construct 2.

    So, I was wondering how to make sure "blocks" (sprites) spawns in an exact pattern (or grid)? I tried my (well, not "my" haha) mathematical equation that used to work the classic version, but it didn't work Construct 2.

    A very quick CAP where I tried to make it: dl.dropbox.com/u/58042250/cap.capx

    The Mathematical equation that I used in classic: floor(MouseX/global('grid'))*global('grid')+global('grid')/2

    floor(MouseY/global('grid'))*global('grid')+global('grid')/2

    Thanks for any attention / help in advance haha :D

  • Dropbox doesn't require the end user to register to download a file and doesn't slow connexions with advertising and unecessary pages.

    Also your equation uses the syntax of construct classic which isn't the case anymore in C2 (don't need the global() stuff, your global variable is named 'grid' ? just write "grid").

    Have a look at this topic (found in the how do I FAQ under the "Tiling/Grid" section), it should help you spawning a grid.

    In the same FAQ you can find examples of tiling/digging game like terraria and loads of other relative stuff.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much for the helpfull advice, and sorry for my rookie mistakes there haha updated the link to a dropbox link (even though I most likely will be able to solve it using the guide haha) :D

  • if your blocks are all square (like minecraft and terraria) then just place em every width/height of the block. If your blocks are 16x16 and the origin is the top left then x+16 would be to the right of the block y+16 would be below it. You dont need complicated formulas or anythin like that all you need is a starting position and a loop to fill any size space with any size blocks.

    If your placin em with a mouse or somethin then you take the mouse position multiply it by the grid size then divide it by the gridsize to force somethin to a grid. Really simple

  • Ah haha thanks :D I was wondering how I should write that out then, like "Mouse.x..." kind of thing, sorry for my newbiness here, I am just clueless haha :D

  • if you still haven't figured it out, use int(mouse.x/16)*16 assuming your tiles are 16x16. This force the position to snap to a 16 by 16 grid

  • Ah thanks haha *feels quite stupid for not figuring it out* Thank you all for the advice and help :) it does seem a little un-precise though, like, clicking on a certain tile and it creates it on the tile above, this happens if I am slightly close to the tile above (yet not fully clicking on the tile above) if you see what I mean haha

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