我正在尝试在 swift SpriteKit(更具体地说是 RPG)上制作游戏。我在让相机跟随我的角色时遇到问题。到目前为止,所发生的只是相机出现在屏幕外,你甚至看不到角色。谢谢!
import SpriteKit
class GameScene: SKScene {
let cam = SKCameraNode()
let james = SKSpriteNode()
override func didMove(to view: SKView) {
self.anchorPoint = .zero
var background = SKSpriteNode(imageNamed: "image-3")
background.size = CGSize(width: 1500, height: 1000);
background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
addChild(background)
view.ignoresSiblingOrder = false
self.camera = cam
let james = Player()
james.size = CGSize(width: 40, height: 40)
james.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2)
james.zPosition = 1
self.addChild(james)
}
override func didSimulatePhysics() {
self.camera!.position = james.position
}
}