# Check tilemap grid for tile

Get help using Construct 2

### » Fri Jan 10, 2014 7:31 pm

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:

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.
B
132
S
45
G
41
Posts: 865
Reputation: 28,676

### » Fri Jan 10, 2014 7:45 pm

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.Magistross2014-01-10 20:01:04
B
81
S
33
G
27
Posts: 1,029
Reputation: 21,143

### » Sat Jan 11, 2014 5:20 pm

@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!
B
132
S
45
G
41
Posts: 865
Reputation: 28,676

### » Mon Sep 29, 2014 10:15 pm

very helpful Magistross, solves the same problem for me! thank you both
B
10
S
4
G
4
Posts: 26
Reputation: 3,205