I'm still pretty new with spritekit/jstilemap/programming in general.
I'm building a racing game with two tilemaps that scroll vertically with parralax. I was wondering if it's possible to update the tilemap without having to remove the current tilemap and create a new one?
This is basically what I'm doing now. Create two tilemaps:
for var i = 0; i < 2; i++
{
//tilemap
var tileMap = JSTileMap(named: "map1.tmx")
//size of tilemap
var rect = tileMap.calculateAccumulatedFrame()
tileMap.position = CGPoint(x: Int(rect.minX)/2, y: i*Int(rect.height))
tileMap.name = "tilemap"
self.addChild(tileMap)
}
And in Update find nodes called tilemap. Move them down and bounce them up if they are low enough. Then if the map has been seen 4 times update the map with a new one by creating a whole new map and then delete the old one. This works but creates a hitch while the new map is loading.
self.enumerateChildNodesWithName("tilemap") {
node, stop in
node.position = CGPointMake(node.position.x,node.position.y-8)
if(node.position.y <= -node.calculateAccumulatedFrame().height) {
self.mapCount += 1
if (self.mapCount <= 3) {
// if map count is less than 3 just show the same map over and over
node.position = CGPointMake(node.position.x, node.position.y+node.calculateAccumulatedFrame().height*2)
} else if (self.mapCount == 5) {
//update map if has been shown 4 times
println("newTILE")
var tileMap = JSTileMap(named: "map2.tmx")
var rect = tileMap.calculateAccumulatedFrame()
tileMap.position = CGPointMake(node.position.x, node.position.y+node.calculateAccumulatedFrame().height*2)
tileMap.name = "tilemap"
self.addChild(tileMap)
//remove old map
node.removeFromParent()
} else if(self.mapCount >= 5) {
node.position = CGPointMake(node.position.x, node.position.y+node.calculateAccumulatedFrame().height*2)
}
}