You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
//
|
|
// SpriteMoople.swift
|
|
// ArkitDoushiQi
|
|
//
|
|
// Created by Enzo JOLYS on 27/05/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import SpriteKit
|
|
|
|
class SpriteMoople : SKNode {
|
|
|
|
static let offset = CGPoint(x: -400, y: -300 )
|
|
static let direction = CGVector(dx: 100, dy: 100)
|
|
|
|
let image:SKSpriteNode
|
|
let ellipse:SKShapeNode = SKShapeNode(circleOfRadius: 40)
|
|
|
|
var cellPosition:CGPoint = CGPoint(x: 0, y: 0) {
|
|
didSet {
|
|
self.position.x = SpriteMoople.offset.x + SpriteMoople.direction.dx * cellPosition.x
|
|
self.position.y = SpriteMoople.offset.y + SpriteMoople.direction.dy * cellPosition.y
|
|
}
|
|
}
|
|
|
|
|
|
init(nameImage:String,couleur:UIColor){
|
|
ellipse.fillColor = couleur
|
|
image = SKSpriteNode(imageNamed: nameImage)
|
|
|
|
super.init()
|
|
self.addChild(ellipse)
|
|
self.addChild(image)
|
|
}
|
|
|
|
|
|
override var isUserInteractionEnabled: Bool {
|
|
get { return true }
|
|
set {}
|
|
}
|
|
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
}
|
|
|
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
|
|
}
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
let localisation = touches.first?.location(in: parent!)
|
|
|
|
if let localisation = localisation {
|
|
|
|
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))
|
|
|
|
self.cellPosition = CGPoint(x: posX, y: posY)
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
|
|
|
|
}
|