The update method behavioral pattern works with the previous game loop pattern and lets you manage the behavior of multiple game characters.

If you’re building a game that has a fixed number of game elements or at least a fixed number at the start of the game and each one just sits there until one piece is moved each turn, then this pattern is not the best choice.

This pattern is perfect for an adventure game where the hero can stumble across a pack of wolves. Some of the wolves will rush the hero while others might try to circle around and attack from the rear. Or even if there are no monsters involved at all and the hero is just walking through town. Unless this is a ghost town, there should be other people and each other character will be busy with personal tasks and errands.

Without this pattern, how would you manage all these diverse situations? Maybe you could put four separate wolves in the game loop but this would quickly make a complete mess of your game loop. Not just with trying to keep track of each of the wolves but more importantly trying to keep track that there should be wolves in the first place.

If it wasn’t for the common application of this technique within game loops, this might not have ever reached the status of a design pattern. It’s really just a collection of derived classes that all override a method called update. What makes this a pattern is that you’ll likely need to do the same thing in any game that has multiple independent game characters.

The episode also describes three design decisions you’ll need to be aware of and give you some guidance for ways to handle them.

  1. The game loop will call update on each game object one after another. Over the course of many frames, this has the appearance of updating each game object at almost the same time. This can cause problems though. Especially when the objects interact with each other.
  2. Anytime you have a collection that you’re iterating through, you need to be careful with modifying the collection while trying to visit each item in the collection.
  3. What’s the scope of the game object collection? You won’t be able to update every object in the entire game in every frame. So you need to plan carefully how to keep track of objects that are too far away to be of immediate concern. The problem though is that the objects could come back into scope and if you handle this wrong, then th game can seem fake.