implemented ButtonEntity
This commit is contained in:
parent
fcf49e656d
commit
94d7be35ff
@ -11,12 +11,21 @@ import SpriteKit
|
||||
|
||||
class ButtonNode : SKSpriteNode {
|
||||
|
||||
var isEnabled:Bool
|
||||
var isEnabled:Bool{
|
||||
didSet{
|
||||
if isEnabled {
|
||||
self.alpha = 1
|
||||
self.childNode(withName: "label")?.alpha = 1
|
||||
} else {
|
||||
self.alpha = 0.3
|
||||
self.childNode(withName: "label")?.alpha = 0.3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let onButtonPress: () -> ()
|
||||
|
||||
init(iconName: String, text: String,isEnabled:Bool, position: CGPoint, onButtonPress: @escaping () -> ()) {
|
||||
|
||||
self.onButtonPress = onButtonPress
|
||||
self.isEnabled = isEnabled
|
||||
let texture = SKTexture(imageNamed: "yellow_button04")
|
||||
|
@ -23,19 +23,15 @@ class MenuScene: SKScene {
|
||||
onButtonPress: {
|
||||
self.loadScene(scene: GameScene(size: self.size))
|
||||
}))
|
||||
|
||||
entityManager.add(Button(name: "settingsButton",
|
||||
iconName: "",
|
||||
text: "Settings",
|
||||
position: CGPoint(x: midX, y: midY - 80 ),
|
||||
onButtonPress: {
|
||||
|
||||
//TODO: create Settings Scene
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
func backgroundInit(){
|
||||
for i in 0...2 {
|
||||
let sky = SKSpriteNode(imageNamed: "SkyBackground")
|
||||
@ -43,7 +39,6 @@ class MenuScene: SKScene {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -61,7 +56,6 @@ class MenuScene: SKScene {
|
||||
node.position.x += (self.scene?.size.width)! * 3
|
||||
}
|
||||
}))
|
||||
|
||||
entityManager.getButtonByName(buttonName: "startGameButton").isEnabled = GameCenterHelper.isAuthenticated
|
||||
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user