我正在制作Pop The Lock游戏。有一个圆圈和一个人。我希望这个人在圆圈前面(这个人应该放在圆圈的顶部)。我尝试使用zPosition方法,但它似乎没有用。这是GameScene.swift文件的代码。
import SpriteKit
class GameScene: SKScene {
var Circle = SKSpriteNode()
var Person = SKSpriteNode()
var Path = UIBezierPath()
var gameStarted = Bool()
override func didMoveToView(view: SKView) {
//Changing the background color of the view
//Creating the Cirle
Circle = SKSpriteNode(imageNamed: "Circle")
Circle.size = CGSize(width: 300, height: 300)
Circle.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
self.addChild(Circle)
//Creating the person
Person = SKSpriteNode(imageNamed: "Person")
Person.size = CGSize(width: 40, height: 7)
Person.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 115)
Person.zPosition = 1
//Rotating the Person By 90 degrees
Person.zRotation = 3.14 / 2
self.addChild(Person)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
Person.zPosition = 1
if gameStarted == false{
MoveClockwise()
} else if gameStarted == true {
}
}
func MoveClockwise(){
let dx = Person.position.x - self.frame.width / 2
let dy = Person.position.y - self.frame.height / 2
let rad = atan2(dy, dx)
Path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: self.frame.width / 2, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 200)
Person.runAction(SKAction.repeatActionForever(follow).reversedAction())
}
func MoveCounterClockwise(){
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}