私はこれを更新コードに入れません。更新セクションが乱雑にならないようにしてください。作業できるのは 16 ミリ秒だけであることを忘れないでください。
代わりに、キャラクター ノードのサブクラスを作成し、position プロパティをオーバーライドします。基本的に言っていることは、カメラがキャラクターから 10 ピクセル離れている場合は、キャラクターに向かって移動するということです。アクションにキーを使用して、複数のアクションが重ならないようにし、タイミング モードを使用して、カメラが瞬時ではなくポイントにスムーズに移動できるようにします。
class MyCharacter : SKSpriteNode
{
override var position : CGPoint
{
didSet
{
if let scene = self.scene, let camera = scene.camera,(abs(position.y - camera.position.y) > 10)
{
let move = SKAction.move(to: position, duration:0.1)
move.timingMode = .easeInEaseOut
camera.run(move,withKey:"moving")
}
}
}
}
編集: @Epsilon は、SKActions と SKPhysics が格納されたプロパティを経由する代わりに変数に直接アクセスすることを思い出させたので、これは機能しません。この場合、 didFinishUpdate メソッドで実行します。
override func didFinishUpdate()
{
//character should be a known property to the class, calling find everytime is too slow
if let character = self.character, let camera = self.camera,(abs(character.position.y - camera.position.y) > 10)
{
let move = SKAction.move(to: character.position, duration:0.1)
move.timingMode = .easeInEaseOut
camera.run(move,withKey:"moving")
}
}