Use Variables to Monitor Game States

In a game like Gloop Drop, you need to monitor a few values and game stats, for example, the current score and level. The GameScene class has a level property that holds the value of the current level, but it doesn’t have a score property to hold the current score—at least not yet. Furthermore, you have labels in the scene that need to get updated when the level and score values change. While you could write a method to update the labels’ text as the player’s score and level change, a better way to keep things in sync is to use a property observer[32] for each property. With a property observer, you can monitor the changes in a property’s value. For Gloop Drop, you’ll monitor the changes for both the level ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.