fix getBackground to return a optional

This commit is contained in:
Niko Jochim 2020-06-18 19:39:59 +02:00
parent b22e645163
commit 3c4ae97b61
3 changed files with 8 additions and 9 deletions

View File

@ -277,7 +277,7 @@ class EntityManager {
}
func getBackground() -> GKEntity? {
return entities.filter{$0 is Background}[0]
return entities.filter{$0 is Background}.first
}
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? {
@ -289,7 +289,7 @@ class EntityManager {
}
func getHUD() -> HUD? {
return entities.filter{$0 is HUD}[0] as? HUD
return entities.filter{$0 is HUD}.first as? HUD
}
func getSnapshotModel() -> SnapshotModel {

View File

@ -77,13 +77,11 @@ class GameScene: SKScene{
}
override func update(_ currentTime: TimeInterval) {
if entityManager.entities.count != 0 {
entityManager.getBackground()?.update(deltaTime: currentTime)
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
gameEnd()
}
}
}
func addAttackDetails(touchLocation: CGPoint){
for base in currentDraggedBase!.adjacencyList {
@ -128,6 +126,7 @@ class GameScene: SKScene{
}
func gameEnd(){
entityManager.getHUD()?.blockWholeScreenPane.isHidden = true
gameEndEffects = true
GameCenterManager.sharedInstance.gameEnded = false
let move = SKAction.move(to: CGPoint(x: self.size.width / 2, y: self.size.height / 2), duration: 1)