3) A visual actor system that works with the rest of the visual presentation to the player independently of game logic and data: the visual aspects of the game are maintained separate from any game logic code; the visual actor system simply listens for game events that it is interested in and makes decisions about what animations to start, queue, replace, skip, etc.
Pro: Far more flexible than the alternatives. Can be much nicer looking.
Con: Much, much more complicated and prone to subtle bugs. Hard to determine if the visual state accurately represents the logical state of the game.
Examples: none that I know of.
I do something a bit like this, which is essentially my own simplified version of the
MVVM pattern used by WPF. This allows me to 'bind' properties of two different objects together. The way it is implemented is something a bit like this:
- Each game object has getter and setter functions for all of its properties.
- In the setter function, I raise a 'propertyChanged' event, passing the property name as an argument
- Other objects can then subscribe to that event. These maintain a list of bound property pairs. When a 'propertyChanged' event gets raised, I use reflection to get the new value of the source property and apply it to the target one.
So, for example, let's say I have a game object A and a visual object B that I want to represent the position of A. I just call:
B.dataContext(A);
B.addDataBinding("position","position");
Then, whenever the 'position' property of A is changed, the 'position' property of B is automatically updated. Where animation comes in is that rather than immediately setting the property on B, I can instead set it up to automatically apply an animation that tweens from the old value to the new one.
Advantages of this system:
- It's super-flexible.
- My game logic and display logic can be completely separate. If I want to move A from X to Y I just set its position to Y. The visual representation B takes care of the tweening - I don't need to pollute my game code to deal with it.
- It's very easy and fast to set up new property bindings, or to completely change the way existing ones work.
- I can easily have multiple visual objects attached to the same game object. For instance in
Hellion, every game object has a 3D sprite in the main view and a top-down sprite in the 2D map.
Disadvantages:
- It was very complicated and took a lot of work to set up in the first place (although now it's there it doesn't give me much trouble).
- Because it uses reflection, it is relatively inefficient. (Although not so much that it's had a noticeable effect in any of the scenarios I've used it in so far.)