How do I get tile ID under mouse pointer or Sprite object

Get help using Construct 2

Post » Sun Jan 24, 2016 4:32 pm

Hello everyone.
Let's say I have top-down game with different types of surface: water, sand, forest, etc. I've created the background with Tilemap object. Type of surface affects gameplay: -50% Move on Sand, +40% Defence in Forest an so on. To apply these conditions I have to read tile ID in Player position. The only way I know - use "Compare Tile At", but if I have, say, 10 different types of surfaces, I have to make 10 events. Is there more elegant way to get tile ID?
Thank you.
B
4
S
1
Posts: 5
Reputation: 312

Post » Sun Jan 24, 2016 6:27 pm

I dont see why you would need 10 events to detect tiles on 1 tile map.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun Jan 24, 2016 8:23 pm

I got it. I can retrive tile ID with "Tilemap.TileAt" with "PositionToTile" as arguments. mindfaQ, thank you for your attention, anyway :)
B
4
S
1
Posts: 5
Reputation: 312

Post » Sun Jan 24, 2016 8:25 pm

Well, it's easy to put the names into an array and then you could easily get the name of the terrain with an expression like:

array.At(tilemap.TileAt(tilemap.PositionToTileX(mouse.X), tilemap.PositionToTileY(mouse.Y)))

That doesn't change the fact that now your gameplay system still does not know the specifics of each terrain field, so you still need to save that data somewhere, either hard code it into the events or (better) put the data into an array... perhaps in the array you now are already using.

So if you only have the speed and defense modifiers, you could easily store the name of the terrain at y-index 0, the speedmodifier at y-index 1, the defense modifier at y-index 2.

and let's say you wanna use your event exampel, then you could write it like:

Compare Tile At (X,Y):
* terrain_type = array.at(tile_ID, 0)
* terrain_speed = array.at(tile_ID, 1)
* terrain_defense = array.at(tile_ID, 2)


If you don't know how to use array... there is plenty of topics, tutorials and the manual, where you can learn how to use them.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786


Return to How do I....?

Who is online

Users browsing this forum: David181, NECRONOMICRON and 27 guests