changed base to SKSpriteNode and add effects touch/move
This commit is contained in:
parent
63e0336413
commit
9a560d2fa0
@ -9,33 +9,63 @@
|
||||
import SpriteKit
|
||||
import GameplayKit
|
||||
|
||||
class Base {
|
||||
var spriteNode: BaseNode!
|
||||
class Base : SKSpriteNode{
|
||||
public static let colorSelected = SKColor.yellow
|
||||
var availableBases = [Base]()
|
||||
var standartColor = SKColor.green
|
||||
|
||||
init(frame: CGRect, color: UIColor, position: CGPoint) {
|
||||
spriteNode = BaseNode(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 50.0, height: 50.0))
|
||||
spriteNode.colorBlendFactor = 1
|
||||
spriteNode.name = "Base"
|
||||
spriteNode.position = position
|
||||
spriteNode.isUserInteractionEnabled = true
|
||||
init(color: UIColor, position: CGPoint, name: String) {
|
||||
super.init(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 50.0, height: 50.0))
|
||||
|
||||
standartColor = color
|
||||
self.colorBlendFactor = 1
|
||||
self.name = name
|
||||
self.position = position
|
||||
self.zPosition = 2
|
||||
self.isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func addAvailableBase(base: Base) {
|
||||
availableBases.append(base)
|
||||
}
|
||||
}
|
||||
|
||||
class BaseNode: SKSpriteNode {
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
print("\(self.name!) was touched and is located at \(self.position)")
|
||||
self.run(
|
||||
SKAction.sequence(
|
||||
[
|
||||
SKAction.resize(byWidth: 20, height: 20, duration: 0.5),
|
||||
SKAction.resize(byWidth: -20, height: -20, duration: 0.5)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
print("\(self.name!) was touched and is located at \(self.position)")
|
||||
self.run(
|
||||
SKAction.sequence(
|
||||
[
|
||||
SKAction.resize(byWidth: 20, height: 20, duration: 0.5),
|
||||
SKAction.resize(byWidth: -20, height: -20, duration: 0.5)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
self.color = SKColor.yellow
|
||||
|
||||
for base in availableBases {
|
||||
base.color = Base.colorSelected
|
||||
base.size = CGSize(width: 60, height: 60)
|
||||
}
|
||||
}
|
||||
|
||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
self.color = standartColor
|
||||
for base in availableBases {
|
||||
base.color = base.standartColor
|
||||
base.size = CGSize(width: 50, height: 50)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
enum PlayerColors {
|
||||
static let colors = [
|
||||
UIColor(red: 231/255, green: 76/255, blue: 60/255, alpha: 1.0),
|
||||
|
Loading…
Reference in New Issue
Block a user