diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 41c82b9..8d513d0 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -33,6 +33,8 @@ 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.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 */ /* Begin PBXContainerItemProxy section */ @@ -86,6 +88,8 @@ 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = ""; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; + C0BB0377245CCF4D00EEAC81 /* BackgroundNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundNode.swift; sourceTree = ""; }; + C0BB0379245CCF6300EEAC81 /* BackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundComponent.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -181,6 +185,8 @@ 9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */, 9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */, 9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */, + C0BB0377245CCF4D00EEAC81 /* BackgroundNode.swift */, + C0BB0379245CCF6300EEAC81 /* BackgroundComponent.swift */, ); path = Components; sourceTree = ""; @@ -375,7 +381,9 @@ 110360D9244B101A008610AF /* GameScene.swift in Sources */, 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, + C0BB0378245CCF4D00EEAC81 /* BackgroundNode.swift in Sources */, 11738A3B24508F68004426F1 /* Unit.swift in Sources */, + C0BB037A245CCF6300EEAC81 /* BackgroundComponent.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, diff --git a/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/Contents.json b/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/Contents.json new file mode 100644 index 0000000..231694f --- /dev/null +++ b/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "SkyBackground.jpg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/SkyBackground.jpg b/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/SkyBackground.jpg new file mode 100644 index 0000000..8b499d5 Binary files /dev/null and b/GoldWars/GoldWars/Assets.xcassets/SkyBackground.imageset/SkyBackground.jpg differ diff --git a/GoldWars/GoldWars/Components/BackgroundComponent.swift b/GoldWars/GoldWars/Components/BackgroundComponent.swift new file mode 100644 index 0000000..8c8d3a8 --- /dev/null +++ b/GoldWars/GoldWars/Components/BackgroundComponent.swift @@ -0,0 +1,29 @@ +// +// 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") + } +} diff --git a/GoldWars/GoldWars/Components/BackgroundNode.swift b/GoldWars/GoldWars/Components/BackgroundNode.swift new file mode 100644 index 0000000..74d61e8 --- /dev/null +++ b/GoldWars/GoldWars/Components/BackgroundNode.swift @@ -0,0 +1,28 @@ +// +// 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 + } + })) + } +}