1

When it comes to SpriteKit, there is not a lot of "Good" tutorials out there, so I call on the Stack overflow Gods to help me out.

I'm building a 2d platformer game for iOS. the map will scroll in all directions depending on character movement. I will implement a parallax background as well, but that is not the question I have for today.

I'm obviously trying to do this the most efficient way as possible so that I can incorporate big levels, but I'm not exactly sure how to do it properly. Do I use a bunch of small images that represent the tiled background or do I use one big one ( I hear this is a no go). Do I use a sprite sheet image with all tiles on it and then chop it up into an array.

I'm not too sure on how to implement an array of images and only show the ones that are on the screen. Do I remove all tiles from the scene, and then check which ones are within the bounds of the camera and add those back to the scene.

I'm looking for any detailed help on how I would implement this specifically for the SpriteKit using swift.

Thanks for any help! I really appreciate it!!!!

Discoveringmypath
  • 1,049
  • 9
  • 23
  • What have you tried so far? This tutorial (https://www.raywenderlich.com/137216/whats-new-spritekit-ios-10-look-tile-maps) seems like a good place to start. – Dave Weston Apr 28 '17 at 02:37
  • I just found out about Tile map nodes, so I'm now looking at that tutorial. Thanks for the reference – Discoveringmypath Apr 28 '17 at 03:02
  • The entire point of tile nodes is to reuse the same textures to reduce texture memory, but you then end up using more CPU usage., So if you see a lot of the same patterns in your bg, you may want to consider using a tile map because the value you would save in usable memory would outweight the CPU time used. If your BG has no repeatable patterns, then you do not want to use tiles. – Knight0fDragon May 01 '17 at 17:39
  • @Knight0fDragon thanks for the explanation. So just to be sure. If I want 1 layer of my background to be a unique image for say an area of 5760x1080 px. I should use 1 image for this, instead of splitting it up into tiles? – Discoveringmypath May 01 '17 at 19:04
  • You are using a lot of texture memory, it would have to be 2 images, since max texture size is 4096x4096 – Knight0fDragon May 01 '17 at 19:07
  • @Knight0fDragon Okay so 2 images would be required for that scenario. I'm assuming that would be a bad idea though. I'm rethinking how I can reuse the same images. I have a background of trees that I made that I form together to make the big image 5760x1080px. Each tree is a little different from the rest. Maybe instead of having all trees be unique I can make tiles out of each tree and then reuse the trees accordingly. Does this sound like a more efficient way of handling this kind of situation? Thanks for the reply. – Discoveringmypath May 01 '17 at 20:20

1 Answers1

1

There is actually a very good way to implement tmx tiled maps in spritekit and has been explained well in the Ray Wenderlich tutorials. The following links should give you everything you need.

Read this to get familiar with tiled maps

Download and import the JSTilemap library into your spritekit project

Read this tutorial to learn how to import tilemaps and work with them on a 2D platformer

For implementing the parallax effect, use different background and foreground objects apart from the actual background image and set the appropriate zPosition for each object so that they objects that are closer are shown over the ones which are farther. And finally, as your player moves forward, and objects move backwards, the closer objects will move much faster than the far objects so set a higher velocity to the closest objects and lower velocity to objects that are far. The background should scroll the slowest. This will give you a nice parallax effect and as is shown in this tutorial.

Also, bless Ray Wenderlich before bed everynight.

  • Thanks for the answer, but I'm not looking to use an external tile system. SpriteKit has a tile map functionality built in. If you are able to explain how to use this properly and efficiently I would accept that as an answer. – Discoveringmypath Apr 29 '17 at 03:42