added moving cloudy background

This commit is contained in:
Niko Jochim 2020-05-01 23:57:23 +02:00
parent d8d80b8eb7
commit 8d1aa1de66
4 changed files with 26 additions and 66 deletions

View File

@ -33,8 +33,6 @@
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
C0BB0378245CCF4D00EEAC81 /* BackgroundNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BB0377245CCF4D00EEAC81 /* BackgroundNode.swift */; };
C0BB037A245CCF6300EEAC81 /* BackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BB0379245CCF6300EEAC81 /* BackgroundComponent.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -88,8 +86,6 @@
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; }; 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
C0BB0377245CCF4D00EEAC81 /* BackgroundNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundNode.swift; sourceTree = "<group>"; };
C0BB0379245CCF6300EEAC81 /* BackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundComponent.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -185,8 +181,6 @@
9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */, 9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */,
9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */, 9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */,
9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */, 9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */,
C0BB0377245CCF4D00EEAC81 /* BackgroundNode.swift */,
C0BB0379245CCF6300EEAC81 /* BackgroundComponent.swift */,
); );
path = Components; path = Components;
sourceTree = "<group>"; sourceTree = "<group>";
@ -381,9 +375,7 @@
110360D9244B101A008610AF /* GameScene.swift in Sources */, 110360D9244B101A008610AF /* GameScene.swift in Sources */,
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */, 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
C0BB0378245CCF4D00EEAC81 /* BackgroundNode.swift in Sources */,
11738A3B24508F68004426F1 /* Unit.swift in Sources */, 11738A3B24508F68004426F1 /* Unit.swift in Sources */,
C0BB037A245CCF6300EEAC81 /* BackgroundComponent.swift in Sources */,
11036113244B3E30008610AF /* MenuScene.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */,
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,

View File

@ -1,29 +0,0 @@
//
// BackgroundComponent.swift
// GoldWars
//
// Created by Tim Herbst on 01.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import UIKit
import GameplayKit
import SpriteKit
class BackgroundComponent: GKComponent {
var sky: BackgroundNode
init(size: CGSize, anchorPoint: CGPoint) {
super.init()
self.sky = BackgroundNode(imageNamed: "cloud")
self.sky.name = "clouds"
self.sky.size = CGSize(width: size.width, height: size.height)
self.sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: anchorPoint.y / 2)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -1,28 +0,0 @@
//
// BackgroundNode.swift
// GoldWars
//
// Created by Tim Herbst on 01.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import UIKit
import SpriteKit
class BackgroundNode: SKSpriteNode {
func update(_ currentTime: TimeInterval) {
scrollBackground()
}
func scrollBackground(){
self.enumerateChildNodes(withName: "clouds", using: ({
(node, error) in
node.position.x -= 2
print("node position x = \(node.position.x)")
if node.position.x < -(self.scene?.size.width)! {
node.position.x += (self.scene?.size.width)! * 3
}
}))
}
}

View File

@ -18,8 +18,21 @@ class GameScene: SKScene{
entityManager.add(Base(textureName: "Base", team: .team1)) entityManager.add(Base(textureName: "Base", team: .team1))
entityManager.add(Base(textureName: "Base", team: .team2)) entityManager.add(Base(textureName: "Base", team: .team2))
entityManager.add(HUD(size: self.size)) entityManager.add(HUD(size: self.size))
initMap() initMap()
createBackground()
}
func createBackground() {
for i in 0...2 {
let sky = SKSpriteNode(imageNamed: "SkyBackground")
sky.name = "clouds"
sky.zPosition = -1
sky.size = CGSize(width: (self.scene?.size.width)!, height: (self.scene?.size.height)!)
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2))
self.addChild(sky)
}
} }
// TODO: Issue #24 create Map generation Service // TODO: Issue #24 create Map generation Service
@ -116,4 +129,16 @@ 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
}
}))
}
} }