Merge branch '28-moving-background' into 'development'

Resolve "Moving Background"

Closes #28

See merge request marcel.schwarz/software-projekt-2!29
This commit is contained in:
Aldin Duraki 2020-05-01 22:16:04 +00:00
commit cda2e08624
6 changed files with 70 additions and 3 deletions

View File

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

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

@ -18,8 +18,21 @@ class GameScene: SKScene{
entityManager.add(Base(textureName: "Base", team: .team1))
entityManager.add(Base(textureName: "Base", team: .team2))
entityManager.add(HUD(size: self.size))
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
@ -116,4 +129,13 @@ class GameScene: 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
}
}))
}
}

View File

@ -13,6 +13,19 @@ 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 {
@ -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
}
}))
}
}