TiledTile properties

I’ve been trying to figure out what the best way would be to define certain properties on tiles in the Tiled map editor. For example certain tiles should be collidable, others consumable, others should trigger a map transition etc. In Tiled it is possible to give tiles a certain property (string, boolean etc.) which should be perfect for this case since all the logic for anything that can happen/trigger on a map is confined to Tiled.

However, in Monogame.Extended I have not found a way to get the properties from those TiledTile, they only seem to have a position and an Id.
Is there a way to get those properties or is it just not supported yet?

If anyone has a suggestion on how to do it differently, it would be great :). Note that I’m using Artemis as Entity Component System so I have my own CollisionDetection and would like to keep most of the game logic in that system.

When you give a tile a property in Tiled, you are putting it on the tile in the Tileset and not on the actual tile on the tile layer. (Wow, could I fit the word tile in there one more time?!) This means if you have a table looking tile in your tileset and give it a boolean property of OnFire and set it to false, every table you put on the layer will have the property OnFire with a value of false.

Now for the bad news. The current release does not allow you to get those properties.

Now for the good news. A recent merge in the develop branch does have this functionality. You can just download that branch and compile (it’s really easy.) If you look at the TiledTile class, there is a new property called TileSetTile. This will have a value if the tileset tile that was used has an animation or has properties, otherwise it is null. This will contain the Properties property you are looking for.

tl;dr - No, it is not implemented in the current release, but it is implemented in the develop branch.

Apologies for the overuse of the words tile and property!

This is great news, and bad news :slightly_smiling:. I had hoped (I didn’t know for sure) that properties where tile and coordinate specific. This way I could specify which tile would (for instance) trigger a transition and to which new screen/map this would be. Since the properties are tileset specific this means that I can’t do this :frowning:.

The great news is indeed the functionality of the TileSetTile property. I wil certainly check out the branch and perhaps I can find alternative usecases for this property :smile:.
Thank you very much for replying and overusing the word tile.

Sooooooooo…
More good news, bad news.
Good news…I noticed that I got fixated on properties for the TiledTile in my previous post and missed giving you a useful answer. There actually is something in Tiled that will give you the functionality you want. It is the Object Layer. You can create shapes or use a tile (including animated ones) on this layer, and each one can have it’s own properties. The other good news is that Monogame.Extended reads those objects and creates a list of TiledObjectGroup objects (which relate to the Object Layers in Tiled) and those will contain a list of TiledObject objects. Look for the property TiledMap.ObjectGroups.

Now the bad news…as stated in issue 125, none of the objects render yet. The other thing you need to know is the X and Y properties on the TiledObject are pixel positions not tile grid positions (i.e. if you have 32x32 tile sizes, the (X,Y) for tile grid position (1,2) would be (32, 64).

As long as you don’t care about displaying anything for the object, just have a transparent tile (or one you wouldn’t mind showing up once the render code is implemented) in your tileset and place instances on your map. Put the custom properties you want on each instance and then in your application write a collision detector to determine if you should do something when hitting it.

I think this functionality can be improved and I have some ideas trying to gel that I would like to discuss with @craftworkgames. As with any piece of actively developed software, keep an eye out for the updates.

@CJRii Thanks so much for helping with this. It keeps me pretty busy these days trying to reply to every post about the library. It’s really great to see the community growing and helping each other. That combined with the wiki will hopefully improve things a lot and leave me more time to actually work on new features.

As for discussing you’re ideas I’m always open to hear them. It might take a couple of days but I always try to reply to every post both here and on github issues.

@stretchhog I don’t think I can add any new informtation to this post but I just wanted to let you know I am listening to every request and trying to make the library as useful as possible.

It’s interesting that you’re using Artemis. I’ve used Entity Component Systems before and I really like them. We’ve considered the idea of including one in the library, but I’m also interested in seeing how it works with a 3rd party library like Artemis. I’d love to hear your experiences with it.

This is very good news :slightly_smiling:. I can use that layer to define transition states, no need to render those. I was aware of the position and coordinates, having (x, y) as (1,2) is perfect. I’m calculating the exact pixel rectangles

You guys are doing an awesome job with this extension and I will definitely keep an eye out for updates.

As I said, I really appreciate the job you guys are doing. Keep it up!. I have to experiment more with Artemis to see how well it fits in with Monogame.Extended but for now it works really well.

Artemis itself is a breeze to use and has all the functionality neccesary for a good ECS framework. It does require a bit of juggling to get it to work with the map (especially collision detection). However, this juggling is certainly worth it, managing game entities with en ECS is really easy and very simple to extend functionality to entities or generate new entities.

For instance:
I’m letting the map being drawn by the spritebatch just like in the demos, which works perfectly. However, for the collision detection system I have created a MapManager that reads a specific layer from TiledMap called ‘collision’ and collects a reference to the TiledTile objects on that layer. I then proceed to create entities for each collidable tile.
This gives me a bunch of entities with a Collision component (not just the entities created from the map). During the update function of the CollisionDetectionSystem I can then proceed to check if the tiles from the layer ‘collision’ collide with other entities like the player, or basically anything with a Collision component. Works like a charm :slightly_smiling:

With the additional tips and help from @CJRii I will now be able to define screen transitions on a separate layer and manage them in the same way with Artemis. This really opens up a LOT of possibilities since I can now define anything map related on the actual map (at least the initial state).

1 Like

Sounds awesome. I might just take a closer look at Artemis myself.