How to make camera follow the player?

浪子不回头ぞ 提交于 2019-12-25 08:47:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!