add background to menu-scene

This commit is contained in:
Niko Jochim 2020-05-02 00:14:21 +02:00
parent 8d1aa1de66
commit 5b7c5039e1
4 changed files with 26 additions and 5 deletions

View File

@ -17,7 +17,8 @@ class GameViewController: UIViewController {
if let view = self.view as! SKView? {
if let scene = SKScene(fileNamed: "MenuScene") {
//scene.scaleMode = .aspectFill
scene.size = self.view.bounds.size
scene.scaleMode = .aspectFill
view.presentScene(scene)
//TODO: create dev profile or remove on delivery
view.showsFPS = true

View File

@ -132,10 +132,7 @@ class GameScene: SKScene{
override func update(_ currentTime: TimeInterval) {
self.enumerateChildNodes(withName: "clouds", using: ({
(node, error) in
// 1
node.position.x -= 2
print("node position x = \(node.position.x)")
// 2
if node.position.x < -(self.scene?.size.width)! {
node.position.x += (self.scene?.size.width)! * 3
}

View File

@ -13,7 +13,20 @@ class MenuScene: SKScene {
var startGameButtonNode:SKSpriteNode!
var settingsButtonNode:SKSpriteNode!
override func sceneDidLoad() {
for i in 0...2 {
let sky = SKSpriteNode(imageNamed: "SkyBackground")
sky.name = "clouds"
sky.zPosition = -1
sky.size = CGSize(width: self.size.width, height: self.size.height)
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2))
self.addChild(sky)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
@ -33,4 +46,14 @@ class MenuScene: SKScene {
}
}
override func update(_ currentTime: TimeInterval) {
self.enumerateChildNodes(withName: "clouds", using: ({
(node, error) in
node.position.x -= 2
if node.position.x < -(self.scene?.size.width)! {
node.position.x += (self.scene?.size.width)! * 3
}
}))
}
}