I’m a beginer with Tiled, and I’m currently wondering if it was designed to provide event making tools. I mean an object on the map that is somehow linked to a script.
Currently, I just create an object layer in which “events” are simple objects with the name of the script I want to link them with. Then, in my project’s code, I get the name of the event and I execute the script with this name.
Was there another way to do this? A specially designed way to link objects with scripts?
I haven’t implemented the proper solution in my game yet (though this may end up being what I use, I haven’t thought this through yet). Currently:
- Place regions on my map.
- Have custom properties on them named ‘OnEnter’ and ‘OnExit’.
- Each of those custom properties has a value that maps to a method name in game.
- When the player enters/exits the region, I use reflection to call the corresponding method.
- I pass in some additional parameters (who is entering, etc) to that method
Ideally, I’d like Tiled to parse my script assemblies for any methods with a specific attribute set (say UseForOnEnter), and gather the parameters those methods expect. A custom UI could be added to have a drop down instead of directly entering the method name, and dynamically build up the parameters too so there is some type checking on the editor side. Since the project is currently just me, I haven’t needed/done this yet
You could build this up with additional things: OnTouch, OnWhatever…
Hi Rich, thanks for your answer! Your way of doing it is very interesting. I’ll check this “region” tool on Tiled