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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access