|
|
@ -16,6 +16,9 @@ class SpriteMeeple : SKNode {
|
|
|
|
let imageNode : SKSpriteNode
|
|
|
|
let imageNode : SKSpriteNode
|
|
|
|
var ellipseNode : SKShapeNode
|
|
|
|
var ellipseNode : SKShapeNode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var originalSize: CGSize
|
|
|
|
|
|
|
|
var originalEllipseSize: CGSize
|
|
|
|
|
|
|
|
|
|
|
|
var cellPosition: CGPoint{
|
|
|
|
var cellPosition: CGPoint{
|
|
|
|
didSet(cellPosition){
|
|
|
|
didSet(cellPosition){
|
|
|
|
self.position.x = SpriteMeeple.offset.x + SpriteMeeple.direction.dx*cellPosition.x
|
|
|
|
self.position.x = SpriteMeeple.offset.x + SpriteMeeple.direction.dx*cellPosition.x
|
|
|
@ -25,9 +28,12 @@ class SpriteMeeple : SKNode {
|
|
|
|
|
|
|
|
|
|
|
|
init(imageNamed imageName: String, size: CGSize, backgroundColor: UIColor, imageRotation : Double = 0){
|
|
|
|
init(imageNamed imageName: String, size: CGSize, backgroundColor: UIColor, imageRotation : Double = 0){
|
|
|
|
imageNode = SKSpriteNode(imageNamed: imageName)
|
|
|
|
imageNode = SKSpriteNode(imageNamed: imageName)
|
|
|
|
imageNode.size = CGSize(width: 80, height: 65)
|
|
|
|
originalSize = CGSize(width: 80, height: 65)
|
|
|
|
|
|
|
|
imageNode.size = originalSize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ellipseNode = SKShapeNode(ellipseOf: CGSize(width: 90, height: 90))
|
|
|
|
originalEllipseSize = CGSize(width: 90, height: 90)
|
|
|
|
|
|
|
|
ellipseNode = SKShapeNode(ellipseOf: originalEllipseSize)
|
|
|
|
ellipseNode.fillColor = backgroundColor
|
|
|
|
ellipseNode.fillColor = backgroundColor
|
|
|
|
|
|
|
|
|
|
|
|
cellPosition = CGPoint(x: 0, y: 0)
|
|
|
|
cellPosition = CGPoint(x: 0, y: 0)
|
|
|
@ -44,8 +50,10 @@ class SpriteMeeple : SKNode {
|
|
|
|
|
|
|
|
|
|
|
|
required init?(coder aDecoder:NSCoder){
|
|
|
|
required init?(coder aDecoder:NSCoder){
|
|
|
|
imageNode = SKSpriteNode(imageNamed: "rat")
|
|
|
|
imageNode = SKSpriteNode(imageNamed: "rat")
|
|
|
|
ellipseNode = SKShapeNode(ellipseOf: CGSize(width: 100, height: 100))
|
|
|
|
ellipseNode = SKShapeNode(ellipseOf: CGSize(width: 0, height: 0))
|
|
|
|
cellPosition = CGPoint(x: 0, y: 0)
|
|
|
|
cellPosition = CGPoint(x: 0, y: 0)
|
|
|
|
|
|
|
|
originalSize = CGSize(width: 0, height: 0)
|
|
|
|
|
|
|
|
originalEllipseSize = CGSize(width: 0, height: 0)
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -53,10 +61,13 @@ class SpriteMeeple : SKNode {
|
|
|
|
set { }
|
|
|
|
set { }
|
|
|
|
get { true }
|
|
|
|
get { true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
|
|
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
|
|
|
|
|
|
|
|
imageNode.size = CGSize(width: imageNode.size.width * 1.1, height: imageNode.size.height * 1.1)
|
|
|
|
|
|
|
|
ellipseNode.path = SKShapeNode(ellipseOf: CGSize(width: originalEllipseSize.width*1.1, height: originalEllipseSize.height*1.1)).path
|
|
|
|
|
|
|
|
self.zPosition = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
if let parent = parent, let position = touches.first?.location(in: parent) {
|
|
|
|
if let parent = parent, let position = touches.first?.location(in: parent) {
|
|
|
|
// Arrondir à la case la plus proche pour x et y
|
|
|
|
// Arrondir à la case la plus proche pour x et y
|
|
|
@ -69,6 +80,11 @@ class SpriteMeeple : SKNode {
|
|
|
|
|
|
|
|
|
|
|
|
self.position = CGPoint(x: clampedX, y: clampedY)
|
|
|
|
self.position = CGPoint(x: clampedX, y: clampedY)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imageNode.size = originalSize
|
|
|
|
|
|
|
|
ellipseNode.path = SKShapeNode(ellipseOf: originalEllipseSize).path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.zPosition = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|