For a project that I am currently working on, I have two SKTileMapNodes stacked on top of each other. They differ in the number of rows, columns as well as tile size. However, it should equate so that they are the same overall width and height.
The problem is that one of the tilemaps is not the right size despite correct rows, columns and tile size.
First SKTilMapNode (Correct Size)
class Map:SKTileMapNode {
func initMap() {
name = "Map"
tileSet = SKTileSet(named: "tileSet")!
numberOfColumns = 32
numberOfRows = 32
tileSize = CGSize(width: 32, height: 32)
position = CGPoint(x: 0, y: 0)
anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fill(with: self.tileSet.tileGroups[4])
}
}
Second SKTileMapNode (Incorrect Size)
class PaintLayer:SKTileMapNode {
func initPaintLayer() {
name = "PaintLayer"
tileSet = SKTileSet(named: "tileSet")!
numberOfColumns = 32*4
numberOfRows = 32*4
tileSize = CGSize(width: 32/4, height: 32/4)
position = CGPoint(x: 0, y: 0)
anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fill(with: self.tileSet.tileGroups[1])
}
}
Initialised In Game Scene
class GameScene: SKScene {
var map:Map = Map()
var paintLayer:PaintLayer = PaintLayer()
var player:Player = Player(imageNamed: "player")
override func didMove(to view: SKView) {
let camera:SKCameraNode = SKCameraNode()
self.camera = camera
self.addChild(camera)
map.initMap()
self.addChild(map)
paintLayer.initPaintLayer()
self.addChild(paintLayer)
player.initPlayer()
self.addChild(player)
}
}
Result