问题
Anybody have a code in swift to make camera follow the player?
Whether to create camera node, like:var camera = SKSpriteNode()
?
回答1:
The above answer is actually wrong, Apple docs provides you with a whole implementation for a camera node (although I've always read it through Objective-C). I'll link you, and others, to the doc in this answer so you can learn it instead of just copy and pasting some code. Hope this helps!
https://developer.apple.com/library/prerelease/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
回答2:
Apple's Adventure game which is the reference implementation for Spritekit has some great code and explanations on "Moving the Camera". It is objective-c but the concepts and code are portable.
回答3:
No, there is no camera-like node. But you can simulate it if you move the background instead of the player.
So if the player walks to the right, the background moves and the player stays at the same place.
来源:https://stackoverflow.com/questions/28302168/how-to-make-camera-follow-the-player