changed base to SKSpriteNode and add effects touch/move
This commit is contained in:
parent
63e0336413
commit
9a560d2fa0
@ -9,19 +9,30 @@
|
||||
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(
|
||||
@ -34,7 +45,26 @@ class BaseNode: SKSpriteNode {
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
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 = [
|
||||
|
Loading…
Reference in New Issue
Block a user