same functionality just cleaned up code
This commit is contained in:
parent
b945f1e236
commit
29adaf14a7
@ -68,7 +68,7 @@ class EntityManager {
|
||||
}
|
||||
|
||||
if let rulesEntity = entity as? Rules {
|
||||
scene.addChild(rulesEntity.node1)
|
||||
scene.addChild(rulesEntity.node)
|
||||
}
|
||||
|
||||
if let wayEntity = entity as? Way {
|
||||
@ -374,7 +374,7 @@ class EntityManager {
|
||||
func removeRules(){
|
||||
entities.forEach({entity in
|
||||
if let rules = entity as? Rules {
|
||||
rules.node1.removeFromParent()
|
||||
rules.node.removeFromParent()
|
||||
|
||||
if let button = rules.component(ofType: ButtonComponent.self) {
|
||||
button.buttonNode.removeFromParent()
|
||||
|
@ -11,11 +11,9 @@ import GameplayKit
|
||||
|
||||
class RulesScene: SKScene {
|
||||
|
||||
var entityManager = EntityManager.rulesEMInstance
|
||||
|
||||
override func sceneDidLoad() {
|
||||
entityManager.setScene(scene: self)
|
||||
entityManager.add(Button(name: "backToMenuScene",
|
||||
EntityManager.rulesEMInstance.setScene(scene: self)
|
||||
EntityManager.rulesEMInstance.add(Button(name: "backToMenuScene",
|
||||
textureName: "yellow_questionmark",
|
||||
text: "",
|
||||
position: CGPoint(x: self.size.width - 50, y: self.size.height - 50),
|
||||
@ -23,7 +21,7 @@ class RulesScene: SKScene {
|
||||
let scene = MenuScene(size: self.size)
|
||||
self.loadScene(scene: scene)
|
||||
}))
|
||||
entityManager.add(Label(fontnamed: "Courier-Bold",
|
||||
EntityManager.rulesEMInstance.add(Label(fontnamed: "Courier-Bold",
|
||||
name: "rulesLabel",
|
||||
text: "Regelwerk",
|
||||
fontSize: 90,
|
||||
@ -34,112 +32,87 @@ class RulesScene: SKScene {
|
||||
isAnimationEnabled: true,
|
||||
isAnimationInfinite: true)
|
||||
)
|
||||
entityManager.add(Button(name: "Spiel",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Spiel",
|
||||
textureName: "yellow_button13",
|
||||
text: "Spiel",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielbeschreibung))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "Basen",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Basen",
|
||||
textureName: "yellow_button13",
|
||||
text: "Basen",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBasen"))
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "Einheiten",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Einheiten",
|
||||
textureName: "yellow_button13",
|
||||
text: "Einheiten",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Einheiten))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesEinheiten"))
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "Spielende",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Spielende",
|
||||
textureName: "yellow_button13",
|
||||
text: "Spielende",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielende))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpielende"))
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "Boost",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Boost",
|
||||
textureName: "yellow_button13",
|
||||
text: "Boost",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Boost))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBoost"))
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "Erfolge",
|
||||
EntityManager.rulesEMInstance.add(Button(name: "Erfolge",
|
||||
textureName: "yellow_button13",
|
||||
text: "Erfolge",
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175),
|
||||
onButtonPress: {
|
||||
self.entityManager.removeRules()
|
||||
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Achievements))
|
||||
EntityManager.rulesEMInstance.removeRules()
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesErfolge"))
|
||||
|
||||
}))
|
||||
entityManager.add(Background(size: self.size))
|
||||
entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen))
|
||||
EntityManager.rulesEMInstance.add(Background(size: self.size))
|
||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
|
||||
}
|
||||
|
||||
func loadScene(scene: SKScene) {
|
||||
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
||||
entityManager.entities.removeAll()
|
||||
EntityManager.rulesEMInstance.entities.removeAll()
|
||||
self.view?.presentScene(scene, transition: transition)
|
||||
}
|
||||
|
||||
override func update(_ currentTime: TimeInterval) {
|
||||
if entityManager.entities.count != 0 {
|
||||
entityManager.getBackground()!.update(deltaTime: currentTime)
|
||||
if EntityManager.rulesEMInstance.entities.count != 0 {
|
||||
EntityManager.rulesEMInstance.getBackground()!.update(deltaTime: currentTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum RulesCategory: String{
|
||||
case Spielbeschreibung
|
||||
case Basen
|
||||
case Spielende
|
||||
case Achievements
|
||||
case Einheiten
|
||||
case Boost
|
||||
}
|
||||
|
||||
class Rules: GKEntity {
|
||||
|
||||
var entityManager = EntityManager.menuEMInstance
|
||||
var node1: SKSpriteNode
|
||||
var node: SKSpriteNode
|
||||
|
||||
init(rulesScene: RulesScene, rulesCategory: RulesCategory) {
|
||||
let texture: SKTexture
|
||||
switch rulesCategory {
|
||||
case .Spielbeschreibung:
|
||||
texture = SKTexture(imageNamed:"RulesSpiel")
|
||||
case .Basen:
|
||||
texture = SKTexture(imageNamed:"RulesBasen")
|
||||
case .Spielende:
|
||||
texture = SKTexture(imageNamed:"RulesSpielende")
|
||||
case .Achievements:
|
||||
texture = SKTexture(imageNamed:"RulesErfolge")
|
||||
case .Einheiten:
|
||||
texture = SKTexture(imageNamed:"RulesEinheiten")
|
||||
case .Boost:
|
||||
texture = SKTexture(imageNamed:"RulesBoost")
|
||||
}
|
||||
node1 = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8))
|
||||
node1.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150)
|
||||
node1.zPosition = 4
|
||||
super.init()
|
||||
init(rulesScene: RulesScene, textureName: String) {
|
||||
let texture = SKTexture(imageNamed: textureName)
|
||||
node = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8))
|
||||
node.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150)
|
||||
node.zPosition = 4
|
||||
super.init()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
Loading…
Reference in New Issue
Block a user