現在、プレーヤーが移動されるたびにカメラを自分の "orb"に追従させようとしています。私はorbが動かされるたびに、orbのx位置にカメラの位置を設定しましたが、何らかの理由でorbが速く動かされると、SKCameraNodeはノードの位置まで追いつくように動かなくなります。実際の更新()の後に物理が実行されるためですが、問題の解決方法はわかりません。この問題を解決する方法はありますか?SKCameraNodeは、プレーヤーが移動するときに遅れます
注:カメラが常に「オーブ」の中心にくるのではなく、むしろオーブをたどるように少し遅らせることで、自由に動く感じを与えます。 (意味がある場合)
import SpriteKit
class GameScene: SKScene {
var orb = SKSpriteNode()
var Touch: UITouch?
let theCamera: SKCameraNode = SKCameraNode()
override func didMoveToView(view: SKView) {
let orbTexture1 = SKTexture(imageNamed:"orb.png")
orb = SKSpriteNode(texture: orbTexture1)
orb.name = "Orb"
orb.position = CGPointMake(300, 95)
self.addChild(orb)
theCamera.position = CGPointMake(300, 0)
theCamera.name = "Camera"
self.addChild(theCamera)
self.camera = theCamera
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
if nodeAtPoint(touch.locationInNode(self)).name == "Orb" {
Touch = touch as UITouch
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
if Touch != nil {
if touch as UITouch == Touch! {
let location = touch.locationInNode(self)
orb.position = location
}
}
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
let action = SKAction.moveToX(orb.position.x, duration: 0.5)
theCamera.runAction(action)
}
}
更新機能内でSKActionsを使用しないでください。 – Abdou023