Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public class GameStateMediator extends State implements ITick{ override public function onRegister():void { facade.registerMediator(new GameHUDMediator); facade.registerMediator(new GameCanvasMediator); // Register any Commands I need to talk to the rest of the system. // Register itself with my game library to receive ticks. } override public function onRemove():void { facade.removeMediator(GameCanvasMediator.NAME); facade.removeMediator(GameHUDMediator.NAME); // Deregister any Commands. // Deregister itself from my game library. } public function onTick():void { // Update physics, player control, etc... // Anything that might be interesting to rest of the system, like the HUD, will cause a sendNotification(). e.g. COMMAND_PLAYER_HEALTH_UPDATED. } override public function handleNotification(n:INotification):void { // Respond to any other parts of the system sending Notifications. }}public class GameHUDMediator extends Mediator implements IViewDelegate{ override public function onRegister():void { // Create my custom library views, with 'this' as a delegate. } override public function onRemove():void { // Destroy my custom library views. } // From IViewDelegate public function onViewRender(v:View):void { var gsp:GameStateProxy = facade.retrieveProxy(GameStateProxy.NAME) as GameStateProxy; // render anything anything the view needs from data retrieved from the GameStateProxy. }}
Actually, I am using the State Machine library, but it ultimately just emits notifications. It doesn't address the structure questions I asked.
I decided to make a State class that derives Mediator. These states are sort of like my 'tasks'. They can register, send and receive Notifications. Still feels wrong though... I'm essentially putting logic in the View layer.
In short: Mediators are the only class that can send/receive notifications....
: shanestevens September 03, 2011, 03:55:20 In short: Mediators are the only class that can send/receive notifications....well.. no. Commands can do it also. logic should not be in mediator or proxy, they must be in commands.Mediators generally listen for note to tell them what to show, and it is best that they should do it ignoring any sort of logic.
Take a look at the HelloFlash demo. Self-directed, mediated objects. Maybe a centralized game loop isn't really the answer for an event driven environment?http://trac.puremvc.org/Demo_AS3_Flash_HelloFlash-=Cliff>