Introduction to the Update Loop

Timothy Meixner
A free video tutorial from Timothy Meixner
Meixner & Ruof
4.5 instructor rating • 27 courses • 51,541 students

Lecture description

A quick look at the update loop implemented in SpriteKit and all the methods it provides for us

Learn more from the full course

Introduction to iOS Game Development with SpriteKit & Swift

Develop your first iOS game using the SpriteKit framework and Swift. A Jump'N'Run with countless awesome features!

10:25:54 of on-demand video • Updated November 2017

  • Thoroughly understand the SpriteKit framework
  • Learn about different Node classes
  • Learn about SKPhysics & SKActions
  • Learn about using the asset catalogue
  • Create amazing worlds and levels with SKTileMapNode
  • Learn game development techniques such as red boxing
  • Develop your own game full of awesome features
  • Get a lot of awesome and unique insights and tips for becoming a top game developer
English [Auto] A major part of this bracket framework that we've already mentioned is the update loop that is provided for us and we now want to take a quick look at how it works and what exactly part of it we can implement five different methods that are Update loop cards for every frame and we can overwrite them in any scene class. We will now talk about them one by one. So we start with the first one which is the main method just called update. If I just start typing update in my class I will get the method proposed and can just hit enter at the override method like this. This is the first method that gets called and initiate the update loop. So let's just add a print statement here that outputs 1. We will use this method to write code that should be executed before rendering the next frame before the frame is rendered. However for more methods get caught after finishing the update method all actions are evaluated. For example animations set an extreme movements update note positions and so on. After that is done we did evaluate actions. Method gets called which we can add just like Update and with it I want to print to now physics gets simulated meaning gravity is applied to any body that is affected by it. Or if two physics body collide the calculations get done. As soon as it's done that simulate physics gets called. Which is the method of our update loop. You might have guessed that this time we will print 3 to our consul moving on. The next thing that happens is that constraints are seen get handled. For example if two nodes are connected and need updates or anything like that after that stunt did apply constraints method gets called and we will print a form to the console in it. Now all that's missing is one method called did finish update which will conclude the update loop. So let's override it just like the others and print the 5 the update loop is now complete and the SKF you were render the new frame and tried to our seen ideally on a device. All of these were run 60 times per second the ominous 60 frames per second that are a known measure in game development and gaming itself. The simulator were probably not even on a really fast computer which these frames per second. Since it must emulate the whole environment on top of running the game still it will be run pretty fast so if you would just run it like this it would heavily spam our Canso. We do not want that. So let's add something to the end of the finished update method which will get caught. Last. I want to set the property is possed of a scene that determines whether or not the update loop is running. So if I set this to true here or update loop should run exactly one time and then stop. If I know run the app I should see the number 1 through 5 in the right order in Arkansas. Since the update loop calls the methods in this order then our loop will stop and we won't get any further output started and we can take a look at the console which shows us exactly what we expected. In reality most of the time we will use the update method to add continuous changes in our game. There are however situations where it makes more sense to use another method like that simulate physics. It really heavily depends on the specific situation. I think it is important though to at least once learn how the update loop of our game engine works and how we are able to use it.