implemented ButtonEntity
This commit is contained in:
parent
fcf49e656d
commit
94d7be35ff
@ -11,39 +11,48 @@ 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")
|
||||
super.init(texture: texture, color: SKColor.white, size: texture.size())
|
||||
self.position = position
|
||||
|
||||
self.onButtonPress = onButtonPress
|
||||
self.isEnabled = isEnabled
|
||||
let texture = SKTexture(imageNamed: "yellow_button04")
|
||||
super.init(texture: texture, color: SKColor.white, size: texture.size())
|
||||
self.position = position
|
||||
let label = SKLabelNode(fontNamed: "Courier-Bold")
|
||||
|
||||
let label = SKLabelNode(fontNamed: "Courier-Bold")
|
||||
label.fontSize = 30
|
||||
label.fontColor = SKColor.black
|
||||
|
||||
label.fontSize = 30
|
||||
label.fontColor = SKColor.black
|
||||
label.zPosition = 1
|
||||
label.verticalAlignmentMode = .center
|
||||
label.text = text
|
||||
label.name = "label"
|
||||
|
||||
label.zPosition = 1
|
||||
label.verticalAlignmentMode = .center
|
||||
label.text = text
|
||||
label.name = "label"
|
||||
|
||||
if !iconName.isEmpty {
|
||||
label.position = CGPoint(x: size.width * 0.25, y: 0)
|
||||
let icon = SKSpriteNode(imageNamed: iconName)
|
||||
icon.position = CGPoint(x: -size.width * 0.25, y: 0)
|
||||
icon.zPosition = 1
|
||||
self.addChild(icon)
|
||||
} else {
|
||||
label.position = CGPoint(x: 0, y: 0)
|
||||
}
|
||||
self.addChild(label)
|
||||
isUserInteractionEnabled = true
|
||||
if !iconName.isEmpty {
|
||||
label.position = CGPoint(x: size.width * 0.25, y: 0)
|
||||
let icon = SKSpriteNode(imageNamed: iconName)
|
||||
icon.position = CGPoint(x: -size.width * 0.25, y: 0)
|
||||
icon.zPosition = 1
|
||||
self.addChild(icon)
|
||||
} else {
|
||||
label.position = CGPoint(x: 0, y: 0)
|
||||
}
|
||||
self.addChild(label)
|
||||
isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
|
@ -12,7 +12,7 @@ class MenuScene: SKScene {
|
||||
|
||||
var entityManager: EntityManager!
|
||||
|
||||
override func sceneDidLoad() {
|
||||
override func sceneDidLoad() {
|
||||
entityManager = EntityManager(scene: self)
|
||||
let midX = self.size.width / 2
|
||||
let midY = self.size.height / 2
|
||||
@ -23,18 +23,14 @@ 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 {
|
||||
@ -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