How to make camera follow the player?


Anybody have a code in swift to make camera follow the player? Whether to create camera node, like:<br />var camera = SKSpriteNode() ?


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!

<a href="https://developer.apple.com/library/prerelease/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html" rel="nofollow">https://developer.apple.com/library/prerelease/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html</a>


Apple's <a href="https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/CodeExplainedAdventure/AdventureArchitecture/AdventureArchitecture.html#//apple_ref/doc/uid/TP40013140" rel="nofollow">Adventure</a> 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.


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.


  • How to specify columns in Swagger
  • What's a better way to swap two argument values?
  • How to use a decaying learning rate with an estimator in tensorflow?
  • How to read JSON-LD data from HTML in Objective-C?
  • Why does Apple use assign rather than weak to store a delegate?
  • Connect Node.js with Oracle on Windows platform
  • Open an application in a space using applescripts
  • JavaScriptCore External Arrays
  • how to populate a SQLite database and use that database in phonegap?
  • Most efficient way to move table rows from one table to another
  • abstracting over a collection
  • Can't remove headers after they are sent
  • UIAlertController button function not working
  • C++ pointer value changes with static_cast
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • Problems installing Yesod for Haskell
  • WPF ICommand CanExecute(): RaiseCanExecuteChanged() or automatic handling via DispatchTimer?
  • Webgrid not refreshing after delete MVC
  • Xcode 4 NSLog Macro link in Xcode 3
  • How to attach a node.js readable stream to a Sendgrid email?
  • Functions in global context
  • Jquery UI tool tip close icon
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Asynchronous UI Testing in Xcode With Swift
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Why is an OPTIONS request sent to the server?
  • RectangularRangeIndicator format like triangular using dojo
  • Cross-Platform Protobuf Serialization
  • JSON with duplicate key names losing information when parsed
  • QuartzCore.framework for Mono Develop
  • XCode can't find symbols for a specific iOS library/framework project
  • Traverse Array and Display in markup
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Revoking OAuth Access Token Results in 404 Not Found
  • SQL merge duplicate rows and join values that are different
  • Qt: Run a script BEFORE make
  • LevelDB C iterator
  • Can't mass-assign protected attributes when import data from csv file
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • How to Embed XSL into XML