How to target a specific tile ID upon collision

2

Attached Files

The following files have been attached to this tutorial:

.capx

tilemap-id-collision-test.capx

Download now 187.26 KB

Stats

1,661 visits, 1,976 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 19 Jan, 2018. Last updated 19 Feb, 2019

Hey Constructors,

This is my first tutorial, so no trolling me! :)

I had a need, in my platformer game, to identify whether or not an enemy was currently overlapping a specific tile ID. I had a basic understanding of the ways C2 identifies multiples of the same source, i.e. sprite clones and the tiling functions. I figured it'd be something along the lines of, "if a sprite is overlapping tile ID #, do this action" type of code, but it wasn't quite that easy, so I went hunting for answers.

I was surprised how little I could find on tile ID with my search attempts. I began to collect the necessary information from other tutorials, and I finally assembled what I needed into my own .capx file.

I assume others have had this need, and perhaps it is already fully explained elsewhere, but here is my .capx file for those that may stumble across this tutorial first.

The answer, in the end, wasn't complicated, I just had to learn that C2 attains a tile's ID through a 2-step process. In the attached .capx file, I've commented within the code to help explain which sections of the event sheet do what. It should be quite clear to intermediate members, and possibly beginners, how this process works.

If I am understanding it correctly, the code needs to, first, obtain, and temporarily store in a variable, the X,Y coordinates of the tile we want to test for overlap. Once the X,Y variable is stored, we can use that with a tilemap expression "Tilemap.TileAt" to obtain that specific tile's ID. Then you could set up a simple trigger/action with this ID knowledge.

All of these steps are commented to the best of my abilities in the .capx file, so grab it, run it, and read it. The event sheet will show you it's really quite simple to do.

.CAPX

tilemap-id-collision-test.capx

Download now 187.26 KB
  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!