SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)


問題描述

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

我目前正在嘗試製作一個“launch(er) game”,即使用 SpriteKit 的 Toss the turle、Learn to fly 和 Burrito Bison 風格的遊戲。我已經使用 SpriteKit 的內置物理原理啟動了啟動工作,但是當我嘗試使用 SKCameraNode 跟隨主角時,似乎總是落後一個(或更多)一步,使主角“搖晃” " 在高速下。

我嘗試使用 SKAction 和 .position‑property 設置相機的位置,結果相同。

我猜這是因為物理更新的速度比實際的 update() 更快,我嘗試搜索有關此的信息,但找到了 zilch。

“啟動”主角的功能:

p>

參考解法

方法 1:

By manually setting the camera position in update, you're delaying the camera movement by at least one frame — physics runs after update, so your camera move happens on the frame after your character moves.

When you use a move action instead of directly setting the position, and giving that action a nonzero duration, you're delaying the camera move even more. (The dt in your code is the time between this frame and the last one before it, and you're applying that time to a future movement.) Because the character is still moving while your action runs, the camera will never catch up — you're always moving the camera to where the character was.

Setting the camera position at all is just making extra work for yourself, though. Use SKConstraint instead, and SpriteKit itself will make sure that the camera position sticks to the character — it solves constraints after physics, but on the same frame.

(by ImNoTreerickster)

參考文件

  1. SKCameraNode doesn't keep up with moving node (CC BY‑SA 2.5/3.0/4.0)

#game-physics #iOS #swift #sprite-kit






相關問題

Android AndEngine:簡單的精靈碰撞 (Android AndEngine: Simple sprite collision)

Box2D - 收集硬幣 (Box2D - collect a coin)

LibGDX - 只有可拖動的運動 (LibGDX - only draggable movement)

Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

2D 平台遊戲:為什麼讓物理依賴於幀率? (2D platformers: why make the physics dependent on the framerate?)

基於脈衝的物理 - 在輕物體上堆疊重物體 (Impulse based physics - Stacking heavy object on light object)

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

向前和橫向球員運動 (Forward and Sideways Player movement)

如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)







留言討論