mfessenden/SKTiled

Reading tile set properties configured with the Object Types Editor

Closed this issue · 7 comments

First of all, great work on this project! I think generally it's easy to use. I forked a branch for tvOS and perhaps I will in the future submit a patch, if I can adapt the Demo project properly for tvOS.

Now for my question ...

In my current level setup I have to following:

  • I have created a tile map that makes use of a tile set.
  • The tile set contains some objects with sprites.
  • I have created Object Types using the Object Types Editor. One of these Object Types is a "Creature". As a property for "Creature" I have added "breed".
  • Within the tile set I assigned the type "Creature" to the tiles. I've set the "breed" property to "player" for 1 tile and "imp" to another tile.

Now it is difficult for me to read this property directly using the SKTiled framework. It seems I have to resort to a bit of "hackery" to read the value for "breed". Currently I do this as follows:

        if let tile = object.value(forKeyPath: "tile") as? SKTile {
            if let breed =  tile.tileData.stringForKey("breed") {
                print("breed: \(breed)")
            }
        }

The "hackery" in this situation is the fact that I use value(ForKeyPath:) to access to tile property, in order for me read the value for the breed property.

I don't know if it's a good idea to make the tile property publicly accessible, but I would like to have some cleaner way to access these kind of properties.

Perhaps I am doing something wrong or perhaps this is an area where the framework could improve.

I think this is definitely an area the API could be improved upon.

I corrected a bug recently where a tile object type property wasn't being read properly from Tiled because the tile data type property overrides it in Tiled, and it made me think about exposing the SKTile.tileData property in the SKTileObject class to give you access to its properties. I'm open to any other ideas you might have as well.

I'm just putting the finishing touches on a big update for tile animations, let me run some tests (need to make sure everything works with Xcode 9 now) and see if I can get it pushed up today for you.

I've pushed the 1.16 update; you can now access object tile data with the SKTileObject.tileData method.

Let me know if this gives you any trouble.

Sounds good!

I actually tried to merge with my fork today, but had some issues when building the SKTiled framework itself. Seems "zlib" has been removed from the root directory, which gives me an import error. Not sure if this removal of "zlib" was intended by you?

I might try to merge with my fork this weekend. Perhaps by re-adding the "zlib" directory after merge is completed.

Are you using Xcode 8?

I've updated the master branch to compile in Xcode 9, which removes the need to import zlib via a modulemap. If you're still in 8, you should be able to restore the zlib from a previous commit and link the framework with the latest. I can add the files back to the master branch if that makes it easier.

Ah, that explains it, I indeed use Xcode 8 (usually I am hesitant to update too quickly to the newest Xcode).

I will probably upgrade to Xcode 9 this weekend. And expect all to be well. Will let you know.

I usually keep the latest two versions of Xcode handy for checking compatibility, but the Apple app store installer took it upon itself to blow away my v8 when it upgraded my v9 beta this week. 😡

I've re-added the zlib directory and also added a temporary branch for Xcode 8.

I've updated my fork today and switched to Xcode 9 as well. I could remove the hacky object.getValue(forKeyPath: "tile") code and just use object.tileData instead. This solution works well for me, so I'll close it.

Because I've updated to Xcode 9, I haven't gotten any zlib issues either anymore, so that's nice.

Thanks!