Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading tile set properties configured with the Object Types Editor #15

Closed
wolf81 opened this issue Sep 20, 2017 · 7 comments
Closed

Reading tile set properties configured with the Object Types Editor #15

wolf81 opened this issue Sep 20, 2017 · 7 comments
Assignees

Comments

@wolf81
Copy link
Contributor

wolf81 commented Sep 20, 2017

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.

@wolf81 wolf81 changed the title Reading properties configured with the Object Types editor Reading tile set properties configured with the Object Types editor Sep 20, 2017
@wolf81 wolf81 changed the title Reading tile set properties configured with the Object Types editor Reading tile set properties configured with the Object Types Editor Sep 20, 2017
@mfessenden
Copy link
Owner

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.

@mfessenden mfessenden self-assigned this Sep 20, 2017
@mfessenden
Copy link
Owner

mfessenden commented Sep 21, 2017

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.

@wolf81
Copy link
Contributor Author

wolf81 commented Sep 22, 2017

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.

@mfessenden
Copy link
Owner

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.

@wolf81
Copy link
Contributor Author

wolf81 commented Sep 22, 2017

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.

@mfessenden
Copy link
Owner

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.

@wolf81
Copy link
Contributor Author

wolf81 commented Sep 27, 2017

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!

@wolf81 wolf81 closed this as completed Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants