Go modular for multiple games?

JeffW.'s Avatar


20 Jun, 2013 08:47 AM


I would appreciate some advice about how to set up my project. Let me describe what I want.

It is an AIR desktop app that shows two games, first game A, then game B, then game A again - but with other content - et cetera.
Game B needs to know a little about Game A, for instance the 'content theme' or the speed.
Both games need to listen to the same sort of data, for instance keyboard input.
Both games share the same views, but only partly, for instance the game over view.
Both games could share the same commands but only partly. For instance, when the keyboard is pressed
a service should send certain data to an external device, but the data are different.

I want to use RL2 because it has a ViewManager which makes it easier for me to work with multiple windows/monitors.

One thing that comes to mind is working with 'modules' which also seems to be possible with RL2, using the ModuleExtension,
but the threads I read about it and the examples I saw look kinda daunting so far.
I also feel I should use a common library that is shared by the two games. And if needed, extended, because another thing that comes to mind is working with inheritance, extending commands and views.
Another thought is create the games in separate RL2 projects - using code from a common lib, compile them as SWFs and load them into a main AIR app.

So I wonder how I can 'add' two games, with their own contexts to a main 'shell' and allow each game to listen to events (signals) dispatched by the main app. Is this possible without going modular?
And do the games need their own contexts? If not, would that not end in a lot of 'if game A ...else if game B...' statements, something I don't prefer?

Sorry if I'm a bit vague and my questions - and the title of this post - may not be very specific, but I hope you can share some thoughts,


Showing page 2 out of 2. View the first page

  1. Support Staff 31 Posted by Ondina D.F. on 21 Jun, 2013 01:51 PM

    Ondina D.F.'s Avatar

    This works!!!

    In ModuleConnectorConfig – only the receiveEvent is set!!

    [Inject (name='siblingChannel')]
    public var siblingDispatcher:IEventDispatcher;
  2. 32 Posted by JeffW. on 22 Jun, 2013 08:28 AM

    JeffW.'s Avatar

    I noticed that when a ModularConnectorEvent event is dispatched in both your and my demo, it initializes the event five times - or less when less modules are added, something I see when I do a trace() call in the constructor of the event. The mediators are receiving the event only once, so that's good. I'm sure this has to do with the inter-modular relaying but was just wondering how this globally works.

    Btw, I'd love to see an extension that makes it possible to use signals for modular relaying and receiving, wouldn't know where to start :)

  3. Support Staff 33 Posted by creynders on 22 Jun, 2013 09:21 AM

    creynders's Avatar

    @Jeffw: yeah, that's the crappy event system, basically the event is cloned for each redispatch. It's to make sure the currentTarget has a dedicated value. If only there was a way to override that behaviour...

    Regarding the signals for modular communication, take a look at this example:

  4. Support Staff 34 Posted by Ondina D.F. on 22 Jun, 2013 09:21 AM

    Ondina D.F.'s Avatar

    One reason for this is the mediator re-dispatching the event.

  5. 35 Posted by JeffW. on 22 Jun, 2013 09:28 AM

    JeffW.'s Avatar

    @creynders yes, I just saw that example, thanks. It doesn't seem to work with ModuleConnector. Hmm, so many options...

  6. Support Staff 36 Posted by creynders on 22 Jun, 2013 09:41 AM

    creynders's Avatar

    @jeffw no it uses solely signals, in which case you don't need the ModuleConnector. Personally, I like signals for dedicated, tight communication: view to mediator, abstract service to concrete service, etc. but not for system-wide communication. Signals are great because you can add them to the API, which makes the communication method explicit. Events are better for system-wide communication because they don't pollute the injector with tons of mappings (sth which happens easily with signals) but obviously this is a matter of preference and coding style.

  7. 37 Posted by JeffW. on 22 Jun, 2013 09:48 AM

    JeffW.'s Avatar

    Does that mean you use both signals and events in one project? I always tried to stay away from that, but maybe in this case I can use signals within my module contexts and events for communication between contexts.

  8. Support Staff 38 Posted by creynders on 22 Jun, 2013 10:15 AM

    creynders's Avatar

    Yes, I use both. But you need to be very strict about how you use them, otherwise it becomes a mess. (i.e. signals are only for this kind of communication and events are only for that kind of communication. No intermingling!!) It takes some experimenting to find the approach that feels 'right'.

  9. Support Staff 39 Posted by creynders on 22 Jun, 2013 10:18 AM

    creynders's Avatar

    I can use signals within my module contexts and events for communication between contexts.

    That could be such an approach, but as I said, make sure you don't violate your own rule.

  10. 40 Posted by alanm on 23 Jun, 2013 12:26 PM

    alanm's Avatar

    @JeffW Is it possible to add the Starling extension to your AS3 example? I've been trying but had no luck. I'm new to Robotlegs 2 so any advice you can give would help. Cheers

  11. 41 Posted by JeffW. on 24 Jun, 2013 10:16 AM

    JeffW.'s Avatar

    @alanm I'm not sure if it is possible, I guess it should be. I am pretty new to RL 2 myself. Have you seen this example? https://github.com/brean/robotlegs2-starling-clock-example/tree/mas...

  12. 42 Posted by JeffW. on 24 Jun, 2013 10:16 AM

    JeffW.'s Avatar

    hi again,

    I have been thinking about how I can work on different levels (common, shell, modules) at the same time without having problems with injections of for instance models into commands that share code that both modules are using (Ondina's example does not contain commands and models).

    I would like to check if my thoughts are correct.
    My shell is responsible for adding and removing modules, and for letting modules know some values based on the previously shown module, for instance speed.

    The modules have their own views, commands, models, services and associative mappings.
    If the modules share code - in a command, model, service or view - I write a super class that contains this code and a sub class for each module with module-specific code.

    For instance, I'll have a super startup command for both modules that will add some views, and each module has a sub startup command in which I inject their own state model, in which some variables are set. If the state models share functionality I can extend them from a super model.

    I should not inject models or services into a super command, because it will give errors.
    Unless both modules have mapped this model or service. Is this correct?

    The ModularConnection events are used when I need to change modules.
    For instance, moduleA lets shell know it is finished, so shell can add moduleB

    Does this make sense?

  13. Support Staff 43 Posted by Ondina D.F. on 24 Jun, 2013 11:23 AM

    Ondina D.F.'s Avatar

    Hi Jeff,

    I’m not quite able to answer your questions right now, because I’m busy writing a Readme for my demo, which is now on github:

    Please take a look at it. Your feedback would be appreciated.

    Ondina's example does not contain commands and models

    Yeah, this demo is concentrating solely on the inter-contexts communication. I’m trying to keep it as simple as possible.

    Integrating commands, models and services could be the subject of another demo, based on this one. But, let me finish this first ;)

    Hopefully someone else will answer your questions today.


  14. 44 Posted by JeffW. on 24 Jun, 2013 06:30 PM

    JeffW.'s Avatar

    hi Ondina,

    I walked through the code in your github commit. You have not changed much, right?
    Nice commenting, great diagrams!

    No comments from my side, only thing I can think of is that the name for ModuleBOrCContext.as may sound a bit messy.

    All by all, still a great example for introducing modular connection.

  15. Support Staff 45 Posted by Ondina D.F. on 25 Jun, 2013 09:31 AM

    Ondina D.F.'s Avatar

    Thanks Jeff, I’m glad you like it.

    ModuleBOrCContext.as may sound a bit messy.

    Tell me about it, very messy!! I got stuck at naming it, and thought I just give it some name to be refactored later. There are other classes, methods and vars as well, that I’d like to rename.

    You have not changed much, right?

    Heh, I guess you're saying it jokingly, because I made lots of changes, actually.

  16. 46 Posted by alanm on 25 Jun, 2013 09:49 AM

    alanm's Avatar

    @JeffW Thanks for the link, it helped me a lot with RL2 syntax. Cheers.

  17. Support Staff 47 Posted by Ondina D.F. on 25 Jun, 2013 09:51 AM

    Ondina D.F.'s Avatar

    Hey Alan,

    Adding to Jeff’s answer.


    There are a few examples using Starling and an extension (SARS). Not sure if they are up to date, though.

  18. 48 Posted by alanm on 27 Jun, 2013 12:57 AM

    alanm's Avatar

    @Ondina Thanks for your demo.

  19. Support Staff 49 Posted by Ondina D.F. on 27 Jun, 2013 07:54 AM

    Ondina D.F.'s Avatar

    @Alan My pleasure! I hope it's useful.

  20. Support Staff 50 Posted by Ondina D.F. on 02 Jul, 2013 07:35 AM

    Ondina D.F.'s Avatar

    I'm closing this for now.

  21. Ondina D.F. closed this discussion on 02 Jul, 2013 07:35 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac