How do I check each tiles of a tilemap

Get help using Construct 2

Post » Wed Jul 12, 2017 10:23 am

Hello I would like to know how I can do to check each tile of a tilemap to create a sprite ex tile = 22
B
7
S
1
Posts: 37
Reputation: 1,049

Post » Wed Jul 12, 2017 12:10 pm

First this about that concept 'index'. An index is the place that 'something' has in a list of 'things'. An index is always zero based. (the first 'something' has place zero in the list)

A tile in a tilemap contains the following info :

Its state (mirrored , flipped ....)
The index of its graphic contents. (iD)
The index of its position on a horizontal row (iX)
The index of its position on a vertical row (iX)

Besides that, Tilemap knows the position for the center of that tile (X and Y in pixels)

Using the Conditions, Actions and Expression for Tilemap can be confusing.
When using the condition 'Compare tile at' (by example) it is asking to input 'Tile X' and 'Tile Y'.
As a beginner you would expect to fill in positions (In pixels)
But when you look at the description then you see that is expecting indexes (iX and iY)

To walk trough a tilemap we need to set up a nested loop.
First for the horizontal row of tiles.
The first tile on a row has index zero.
The last tile on a row has index round(tilemap.Width / size of 1 tile)
Then a sub condition for the vertical columns.
The first tile on a column has index zero.
The last tile on a row has index round(tilemap.Height/ size of 1 tile)

Looks like this

Root Event > System > For > Name = "iX" ... start = zero ... end = round(tilemap.Width / size of 1 tile)
Sub event > System > For > Name = "iY" ... start = zero ... end = round(tilemap.Height/ size of 1 tile)

That is the nested loop. The index of the loop we access with the expression loopindex("name")

So we continue with another sub event.
Tilemap > Compare tile at > Tile X= Loopindex("iX") ... Tile Y = Loopindex("iY") ... Tile = iD

But often you need the iX and iY for a tile that is nearest to (lets say) Player.X and Player.Y.
In that case we have to translate X & Y (positions) to iX & iY (indexes)

Tilemap can translate those (positions to indexes) with the expressions Tilemap.PositionToTileX & Tilemap.PositionToTileY
So, to compare a tile near the player :

Tilemap > Compare tile at > Tile X = Tilemap.PositionToTileX(player.X) ... Tile Y = Tilemap.PositionToTileY(player.Y)

I think met this info, you have the base to understand the manual about Tilemap, and figure out the rest yourself.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jul 12, 2017 9:12 pm

Merci pour tout ...

It works but I just realized that its too much resource for the big maps I have to look for that it only acts on a fixed distance between the set and the player
B
7
S
1
Posts: 37
Reputation: 1,049

Post » Wed Jul 12, 2017 9:26 pm

That is what the LOS does already. (had that covered)
There is no distance calculation faster and less resource demanding than the LOS.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: plinkie, Yahoo [Bot] and 19 guests