Discoveringmypath
Discoveringmypath

Reputation: 1077

How to implement a SpriteKit tiled background 2d Platform

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!!!!

Upvotes: 1

Views: 1263

Answers (1)

Souritra Das Gupta
Souritra Das Gupta

Reputation: 130

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.

Upvotes: 1

Related Questions