Kodeco Forums

What’s New In SpriteKit on iOS 10: A Look At Tile Maps

Learn how to use Tile Maps in SpriteKit on iOS 10.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1079-what-s-new-in-spritekit-on-ios-10-a-look-at-tile-maps
1 Like

I can’t wait to go through this and then go through Ray’s Platformer book again with XCodes new tilemap. It’ll make things so much more streamlined.

Applaud for WWDC and Apple on this one.

1 Like

It’s probably worth noting that in the Assets collection that the set folder must NOT have Provide Namespaces checked. And I think it can’t have spaces in the words of each Image set inside it. Otherwise you will get heap errors from malloc not knowing where the asset is.
And in Xcode Version 8.0 beta (8S128d) anyways, a generous use of Product → Clean. :wink:

1 Like

@demzpaul - Thanks for pointing these out.

Yes, definitely Product -> Clean and also Exit Xcode and the Simulator occasionally.

I’ve also found that resetting the Simulator sometimes helps - that’s Simulator -> Reset Contents and Settings.

From what I can tell the Tile Map don’t work on devices right now (at least 32bit, haven’t tried my 64bit devices yet). I was working on my own project which was working fine in the simulator but would consistently crash when attempting to run the map on the device. I decided to try using this sample project on my device and it immediately crashed with the same error.
In both cases the error is:
[NSKeyedUnarchiver decodeInt32ForKey:]: value (9223372036854775807) for key (_defaultTileGroupIndex) too large to fit in 32-bit integer’
I may be missing something but hopefully this is fixed in the next beta…

1 Like

@bcortens - it may be true that they don’t work on 32-bit devices yet. My 32-bit devices are too old to upgrade to iOS 10.

While developing Rubber Duckie Rescue, I was running it on my iPhone 6s running iOS 10 and it worked fine. Much better than in the simulator. The simulator can’t run at 60 fps.

[I assume you’ve updated your device to iOS 10 to be able to run the tile maps. (Caution - only update devices which you don’t mind if they get stuffed up.)]

Yep, I’ve noticed that the simulator doesn’t work well which is why I was trying to get it running on the iPhone 5 I have as a secondary phone. I’ll try installing it on a newer device and see what happens. Thanks for letting me know it works on your iPhone 6s that does make narrow down the list of possible points of failure.

this is awesome and exactly what i was looking for after watching the WWDC session! love it. I built and run on an iPod Touch 6th gen I got just for doing iOS10 dev messing like this !

anyway works great, love the tutorial, interesting way of doing things and really like the tile map stuff… i never planned a game using tile maps, but now i am inspired to come up with something !!

one thing - there are some tiny gaps around the grass edges when i run on the iPod. must be a single pixel off somewhere in the asset graphics?

thanks for this great tutorial !

  • Adam.

just wondering - is there a best practice for the pixel size of the graphics assets used in tiles ?

also - if the map is bigger than the viewable area on screen - how best to scroll ?

:slight_smile:

Thanks, Adam :smiley:

I don’t know why there would be a pixel gap around the edges. There isn’t one on the 6s. I don’t really want to upgrade my other devices at this time, so I can’t check, but I’d be really interested to know what’s going on. It may be fixed in future betas.

The SKTileMapNode is a subclass of SKNode, so you can move it around just as you can any SKNode.

As for best practice, tiles are generally 16x16, 32x32, 64x64, 128x128 etc. I believe the size would be for efficiency, but I can’t find a reference at the moment.

here is how it looks on my iPod Touch.

I’ll check if i did something wrong with an offset or position or something ! if not, then it must be an Xcode bug i guess. it doesn’t look like that in the simulator.

1 Like

simulator screen shot (iPhone SE size)

i filed a bug report as i couldn’t see anything in the code or tile maps that would make the pixel gap happen !
27074864

There is a bit of consistency in the breaks, but perhaps I’m seeing patterns where none exist. In any case, as it works on my iPhone 6s, I think it’s a bug :slight_smile:.

This is definitely my favorite part of this WWDC :heart_eyes_cat:

Finally, we can make games “nearly” as easily as with RPG Maker from 20 years ago (my first experience making a game as a kid, was to remake Pokemon Green on PC with colors, mp3 musics and much better attack effects :heart_eyes_cat:)

Hopefully we’ll get some good tutorials using TileMap, GameplayKit and GKNoise (for procedural mapping).

It would be really nice also if we had a small community sharing some higher quality tilemaps (especially that it supports animations now).

BTW, anyone knows TilemapKit? … As much as I was happy during the presentation at WWDC, I had some strange after taste, did Apple “plagiarize” TilemapKit, or possible bought it?
Really strange that besides animated tiles, they did a perfect carbon copy of TilemapKit :eyes:.

1 Like

I’ve been experimenting with this myself. And have a couple of questions I hope someone can help me with:

  1. There is no way to have tiles with physicsBodies, right? (I’ve created logic to add invisible spriteNodes with physicsBodies based on the tile-type)

  2. Is there any way to use your own types in the UserData-setting (an enum for instance)? Guessing, no, but hoping I’m wrong.

@nickfalk -

  1. The only tile class that can have physics bodies is SKTileMapNode. You can add an array of physics bodies to your tile map node. You don’t have to create separate sprites.

  2. The userData is an NSMutableArray type. I think you can have anything in there that you can store in an NSMutableArray (although your own types are only available in code, not the editor dropdowns naturally). With enums, you could make them integer enums and store the integer raw value.

Thanks!
Self-facepalm on the physics-bodies on the SKTileMapNode bit. I was too focused on the rows and columns to think about the fact that these were obviously available directly as well. (A nice little “can’t see the forest…”-moment).

I was thinking in regards to the dropdown-menus actually, hoping that something akin to SKInspectable, IBDesignable would allow me to access my own enums from the editor. Matching the integers with the enum-rawValues might be a decent work around though, so thanks again!

Caroline, can you help me with physics bodies please?
I do not how to “add an array of physics bodies to my tile map node”

And, can i check tiles example:
if tile.name == “Wall” {
make something
}

Thanks!