Creating a GlideScene from a SpriteKit scene(sks) file:

May 6, 2019 ยท View on GitHub

glide

Creating a GlideScene from a SpriteKit scene(sks) file:

1. Create some tile sets:

2. Create a scene file:

  • Create a SpriteKit Scene file within your Xcode project.
  • Create two tile map nodes under your scene, both positioned at zero.
  • Specify their tile size and map size. Tile size should be same for both.
  • Name your tile maps as you wish, but you need to name them to reach them back after loading the sks file to populate your GlideScene.
  • Populate your tile map nodes with the tile sets you created in previous step. Populate one of them as collidable tile map, and the other one as decoration tile map. Feel free to create more than one decoration tile map nodes.

3. Create a GlideScene

Having your sks map and tile set files included in your Xcode project, use the below snippet to create a GlideScene.

// Load a SKScene with your scene file.
let sks = SKScene(fileNamed: <#T##name of your sks file#>)
guard let collisionTileMap = sks?.childNode(withName: <#T##name of your collision tile map#>) as? SKTileMapNode else {
	fatalError("Couldn't load the collision tile map")
}
var decorationTileMaps: [SKTileMapNode] = []
// Remove nodes from loaded scene to prevent double parent crash.
if let decorationTileMap = sks?.childNode(withName: <#T##name of your decoration tile map#>) as? SKTileMapNode {
	decorationTileMap.removeFromParent()
	decorationTileMaps.append(decorationTileMap)
}
collisionTileMap.removeFromParent()

// Create your scene
let scene = GlideScene(collisionTileMapNode: collisionTileMap, zPositionContainers: <#T##[ZPositionContainer]#>)

/// Add your decoration tile maps in appropriate z position container nodes.
/// e.g. addChild(frontDecorationBackground, in: DemoZPositionContainer.frontDecoration)
/// Alternatively, do this in a custom `GlideScene` subclass.

/// Then present your scene
skView.presentScene(scene)