import SpriteKit
import GameplayKit
class GameScene: SKScene {
let label = SKLabelNode(fontNamed: "HelveticaNeue-Light")
let button = SKSpriteNode(imageNamed: "blue2.png")
let button2 = SKLabelNode(text: "Button")
var n = 0
let label2 = SKLabelNode(text: "kaisu: 0kai")
override func didMove(to view: SKView) {
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
self.backgroundColor = .green
label.text = "Hello World!"
label.position = CGPoint(x: self.frame.midX, y: self.frame.midY + 10)
label.fontSize = 20
label.fontColor = SKColor.white
self.addChild(label)
let labelSize: CGFloat = 30.0
label2.fontSize = labelSize
label2.fontName = "Avenir-Black"
label2.position = CGPoint(x:self.frame.midX, y: 200)
label2.fontColor = SKColor.black
self.addChild(label2)
button.position = CGPoint(x: size.width/2, y: size.height/2+120)
button.zPosition = 1
button.name = "button"
button.setScale(0.4)
self.addChild(button)
button.run(SKAction.scale(to: 0.5, duration: 0.3))
button.alpha = 1
button2.fontName = "HelveticaNeue-Bold"
let labelSize2: CGFloat = 30.0
button2.fontSize = labelSize2
button2.position = CGPoint(x:self.frame.midX, y:250)
self.addChild(button2)
button2.name = "button2"
button2.color = .blue
}
override func touchesEnded(_ touches: Set, with event: UIEvent?) {
button.alpha = 1
button.setScale(0.5)
}
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
guard let touch = touches.first else { return }
let toucLocation = touch.location(in: self)
button2.position.x = toucLocation.x
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let tappedNodes = nodes(at: location)
for node in tappedNodes {
if node.name == "button" {
button.alpha = 0.5
button.setScale(0.6)
if label.fontSize < 50 {
label.fontSize += 2
}
else{ label.fontSize = 20
}
} else if node.name == "button2" {
button2.fontSize += 1
n += 1
label2.text = "kaisu: \(n)kai"
if button2.fontSize >= 50{
button2.fontSize = 30
}
}
}
}
}