game mouvement finie

pull/24/head^2
Your Name 11 months ago
parent bfa8323744
commit b5e73536d3

@ -13,9 +13,6 @@ class SpriteMoople : SKNode {
static let offset = CGPoint(x: -400, y: -300 ) static let offset = CGPoint(x: -400, y: -300 )
static let direction = CGVector(dx: 100, dy: 100) static let direction = CGVector(dx: 100, dy: 100)
static let o = CGPoint(x: 100, y: 300 )
static let l = CGVector(dx: -100, dy: -100)
let image:SKSpriteNode let image:SKSpriteNode
let ellipse:SKShapeNode = SKShapeNode(circleOfRadius: 40) let ellipse:SKShapeNode = SKShapeNode(circleOfRadius: 40)
@ -38,41 +35,35 @@ class SpriteMoople : SKNode {
override var isUserInteractionEnabled: Bool { override var isUserInteractionEnabled: Bool {
get { get { return true }
return true set {}
}
set {
// ignore
}
} }
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
self.position = touches.first?.location(in: self) ?? CGPoint(x: 0, y: 0) self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
} }
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
self.cellPosition = findCellPosition(pos: touches.first?.location(in: self)) let localisation = touches.first?.location(in: parent!)
}
if let localisation = localisation {
func findCellPosition(pos:CGPoint?) -> CGPoint{
if let pos = pos {
print("o : \(SpriteMoople.o.x)")
print("l : \(SpriteMoople.l.dx)")
print("pos : \(pos.x)")
print("X : \(pos.x / SpriteMoople.o.x)") if (localisation.x > 400 || localisation.x < -400 || localisation.y < -300 || localisation.y > 300){
print("Hors limite !")
return
}
let posX = Int(round((localisation.x - (-400)) / 100))
let posY = Int(round((localisation.y - (-300)) / 100))
//print("Y : \(SpriteMoople.offset.y + SpriteMoople.direction.dy / pos.y)") self.cellPosition = CGPoint(x: posX, y: posY)
return
return CGPoint(x: SpriteMoople.o.x - SpriteMoople.l.dx / pos.x, y: SpriteMoople.offset.y - SpriteMoople.direction.dy / pos.y)
} else {
return self.cellPosition
} }
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }

Loading…
Cancel
Save