How to use TileAt(tileX, tileY)

Get help using Construct 2

Post » Thu Dec 12, 2013 3:19 am

I have a large tilemap output on my game with a variety of tiles and I'm wanting to get the tile ID at the Mouse's location on the map.

When my mouse clicks, I'm have a textbox set the text to "map.TileAt(map.PositionToTileX(mouse.X), map.PositionToTileY(mouse.Y))"

But the textbox just outputs constantly "526870911"

I tried simplifying my output to "map.TileAt(1,5)" and various locations but I still get the exact same output "526870911"

Any ideas?
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Thu Dec 12, 2013 8:59 am

Would this be any good:

Text - Set Text to "X: " & Tilemap.PositionToTileX(Mouse.X) & newline & "Y: " & Tilemap.PositionToTileX(Mouse.Y)
If your vision so exceeds your ability, then look to something closer.
Moderator
B
131
S
29
G
81
Posts: 5,328
Reputation: 56,630

Post » Thu Dec 12, 2013 1:34 pm

Sounds like it might be a bug - post a minimal .capx reproducing it to the bugs forum.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Fri Dec 13, 2013 1:32 am

I created a minimal .capx and it worked so I rebuilt my original game and it works now too. Not sure how I fixed cause my original game was very minimal as well but it works...
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Fri Dec 13, 2013 12:29 pm

Use this

text - set text to map.tileAt(mouse.x, mouse.y)

this will report whichever tileID is under the mouse at any given time.

you were close at first :)
B
83
S
39
G
15
Posts: 984
Reputation: 16,741

Post » Fri Dec 13, 2013 1:17 pm

I found TileAt does report the wrong value for empty tiles - from the next build it will return -1.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Sat Dec 14, 2013 12:31 am

Actually that won't work. The parameters for the TileAt method requires tile coordinates arguments. So you must convert the mouse coordinates to tile coordinates first using the positionToTileX and positionToTileY methods. My program is working now using those methods.
B
10
S
3
Posts: 102
Reputation: 1,888


Return to How do I....?

Who is online

Users browsing this forum: DjowG and 9 guests