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

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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.

  • I dont see why you would need 10 events to detect tiles on 1 tile map.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got it. I can retrive tile ID with "Tilemap.TileAt" with "PositionToTile" as arguments. mindfaQ, thank you for your attention, anyway

  • 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 =, 0)

    * terrain_speed =, 1)

    * terrain_defense =, 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.

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