Creating a GlideScene from a Tiled Map Editor map file:
May 9, 2020 ยท View on GitHub
Creating a GlideScene from a Tiled Map Editor map file:
1. Create a map in Tiled Map Editor:
- Download Tiled Map Editor. Tested and working versions are
1.2.1,1.2.2and1.2.3.
2. Create a collidable layer in your Tiled map:
- Now that you have your collidable tiles defined, you can start painting with them, but you need a
Groundlayer to paint on.
-
ground: regular ground collider. -
one_way: one way ground collider. Note that, this kind of tile is not intended to be stacked up vertically and can be used as horizontal platforms in 1 tile height. -
jump_wall_right: jump walls facing left. -
jump_wall_left: jump walls facing right. -
slope_0_3,slope_4_7,slope_8_11,slope_12_15: slope with a proportional angle of 1:4 climbing down to the right. -
slope_15_12,slope_11_8,slope_7_4,slope_3_0: slope with a proportional angle of 1:4 climbing up to the right. -
slope_0_7,slope_8_15: slope with a proportional angle of 1:2 climbing down to the right. -
slope_15_8,slope_7_0: slope with a proportional angle of 1:2 climbing up to the right. -
slope_0_15: slope with a proportional angle of 1 climbing down to the right. -
slope_15_0: slope with a proportional angle of 1 climbing up to the right. -
Collidable layer in your map is for collision handling purposes and not meant to be visible. However, you can see your collidable layer in debug mode. See
GlideScenefor more details.
3. Create some decoration layers in your map file:
- You need to create a custom tileset in Tiled Map Editor in order to create and paint a decoration layer.
-
Now that you have a decoration tile set created and defined you can start painting a decoration layer in your map.
-
Create a new
Tile Layerunder theLayerspane of Tiled Map Editor and name it anything you want. -
Start painting your new layer with the tiles in your decoration tile set.
-
By default, all the layers in your map that are not named
Groundwill be added to yourGlideSceneinstance. To prevent a layer from showing up in your scene, set a customshouldSkip(int) field as1inPropertiespane for this layer in Tiled Map Editor. -
By default, all tile layers in your map are positioned at the same center by the scene by default. However, you can customize that behavior in your
GlideScenesubclasses.
Collidable layer offsets
-
horizontalOffset(int): Amount of tiles that will be cut from left and right sides of the collision tile map. Should be a positive value.
-
verticalOffset(int): Amount of tiles that will be cut from top and bottom sides of the collision tile map. Should be a positive value.
4. Create a GlideScene
Having your tile set and tile map json files included in your Xcode project, use the below snippet to create a GlideScene.
// Create a loader with your json file
let loader = TiledMapEditorSceneLoader(fileName: <#T##json map file name#>,
bundle: Bundle.main,
collisionTilesTextureAtlas: <#T##collisionTilesAtlas#>,
decorationTilesTextureAtlas: <#T##decorationTilesAtlas#>)
guard let sceneTileMaps = loader.tileMaps else {
fatalError("Couldn't load the level file")
}
// Create your scene
let scene = GlideScene(collisionTileMapNode: sceneTileMaps.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)