0
我想寫一個簡單的遊戲,通過點擊時環(不斷變大和變小)在靜止環內進行評分,但我無法弄清楚如何檢測當兩個節點相交時或當移動環位於靜止環內時。如果某人在兩個節點大小相同的情況下點擊,或者如果移動節點位於固定節點內,有人可以向我展示如何添加分數。檢測2個節點在每個軸上的相交情況
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var Circle = SKSpriteNode()
var Circle2 = SKSpriteNode()
var GameStarted:Bool = false
var Path = UIBezierPath()
var run1 = false
var called = true
var intersected = false
override func didMove(to view: SKView) {
Circle = SKSpriteNode(imageNamed: "Circle")
Circle.size = CGSize(width: 100, height: 100)
Circle.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
self.addChild(Circle)
Circle2 = SKSpriteNode(imageNamed: "Circle2")
Circle2.size = CGSize(width: 760, height: 760)
Circle2.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
self.addChild(Circle2)
Circle.zPosition = 0.1
Circle2.zPosition = 0.2
var path = UIBezierPath(arcCenter: CGPoint(x: 15, y: 15), radius: CGFloat(10), startAngle: 0, endAngle: CGFloat(2*Double.pi), clockwise: true)
UIColor.blue.setStroke()
}
func scaleCircle2(){
let duration = 5.0
let scaleAction2 = SKAction.scale(to: CGSize(width: 760, height: 760), duration: TimeInterval(duration))
let scaleAction = SKAction.scale(to: CGSize(width: 15, height: 15), duration: TimeInterval(duration))
let pulse = SKAction.sequence([scaleAction,scaleAction2])
let forever = SKAction.repeatForever(pulse)
Circle2.run(forever)
}
func scaleCircleUP(){
let duration2 = 0.5
let initialsize = 100
let scaleAction3 = SKAction.scale(to: CGSize(width: initialsize + 100, height: initialsize + 100), duration: TimeInterval(duration2))
Circle.run(scaleAction3)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
GameStarted = true
if GameStarted == true{
callCircle2()
}
}
func callCircle2(){ //makes sure scaleCircle2 isn't called twice
if called == true{
scaleCircle2()
}
called = false
}
}