Check tilemap grid for tile

0 favourites
  • 4 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hello,

    I've got a system going where I can load a tilemap when the game begins, and I'm wondering if there's a way to check for all the tiles on it so I can create objects as soon as it opens.

    For instance, here:

    <img src="http://i.imgur.com/CpCf3O3.png" border="0" />

    The tiles with sad faces are supposed to spawn enemies. So what I'm trying to do is:

    1. Create the tilemap

    2. Check if there are sadface tiles by using the tile number (it's number 9)

    3. Create enemies on their X and Y coordinates

    4. Erase them

    I think the ideal thing was to have a For Each Tile, but since this isn't implemented, I'm wondering if there's a way to check the X and the Y of the tilemap using regular for..

    Any ideas?

    Cheers.

  • There doesn't seem to be an easy way to achieve that, although it's far from impossible.

    Try a for loop, start index 0 to floor(tilemap.width / "tile width") - 1, with a nested for loop that goes like start index 0 to floor(tilemap.height / "tile height") - 1. Since there is no expression to retrieve the tile width/height, you'll have to use the same constants as the tilemap properties.

    In the inner loop, add a new condition that goes like compare tile at x = loopindex("outerloop"), y = loopindex("innerloop") equals to 9, then add your actions to create an enemy.

    edit : Here's a quick example. I replace all cacti by mad faces.

  • Magistross

    Oh wow, thanks a bunch, that's exactly what I was going for. I got as far as making the nested loop, but I had no idea you could use loopindex("nameoftheloop") haha. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • very helpful Magistross, solves the same problem for me! thank you both

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