I'm trying to make my first game using SpriteKit & Swift. I think I understood the concept of World SKNode, but I can't make it work properly.
I add world:SKNode
as a child to the GameScene. Then I add 9 child SKSpriteNodes (400px X 400px from starting from 200px X 200px point, because spritesNodes are centered). And they position perfectly, BUT I can't figure out how to get bounds of my world SKNode.
For example, how can I show left down corner of my world?
import SpriteKit
class GameScene: SKScene {
let cityPartSide:Int = 400
let startCoord:Int = 200
var world:SKNode = SKNode()
override func didMoveToView(view: SKView) {
//self.world = SKNode()
self.world.name = "world"
self.addChild(self.world)
let map:[[UInt8]] = [[16, 16, 16],
[16, 16, 16],
[16, 16, 16]]
drawMap(world, map: map)
}
func drawMap(world:SKNode, map:[[UInt8]]) {
let lineSize:Int = map[0].count
var lineCounter = map.count
while lineCounter > 0 {
lineCounter -= 1
var elemCounter = 0
while elemCounter < lineSize {
var sprite:SKSpriteNode = SKSpriteNode()
let currentPartNumb = map[lineCounter][elemCounter]
if currentPartNumb == 0 {
elemCounter += 1
continue
} else {
sprite = SKSpriteNode(imageNamed: "cell")
}
//CHOOSE IMAGE
sprite.position = CGPoint(x: startCoord + elemCounter * cityPartSide, y: startCoord + ((lineSize-1)-lineCounter)*cityPartSide)
world.addChild(sprite)
elemCounter += 1
}
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
But what I get by running this code is that vertically it is positioned perfectly, but left side of the world is somewhere out of the screen.