Is there a way to disable the default reaction to Event.ADDED for specific components

Piers's Avatar

Piers

21 Jan, 2010 12:44 AM

Hi,

I'm working on a game, and am using RobotLegs to build the UI part of the game (popups, forms, score tables etc), but I don't want to use it for the core game engine (it's critical that this part performs very quickly, and so I want to avoid any necessary overhead).

I've got everything set up and running very nicely, and have sectioned the core game part off into a component called GameComponent, which is mediated by a GameMediator class for any times when it needs to communicate with the UI. However, as there are a lot of addChild() and removeChild() calls going on within the GameComponent, there are a lot of necessary onViewAdded() calls going on automatically in the MediatorMap.

I've tried adding a listener for Event.ADDED at the top level of my GameComponent class, and using event.stopPropagation() in the handler, but of course because MediatorMap is listening to the capture phase, it picks up the event before my classes do. I don't suppose there's a way I can exclude children of particular classes from alerting MediatorMap?

I thought perhaps I could just add my GameComponent class directly to the root stage, so as to avoid it being a contextView child altogether, and then just manually set up the GameMediator. Is this the best way?

  1. 1 Posted by Piers on 21 Jan, 2010 12:47 AM

    Piers's Avatar
    • edit: read 'unnecessary', not 'necessary' !
  2. Support Staff 2 Posted by Joel Hooks on 21 Jan, 2010 12:50 AM

    Joel Hooks's Avatar

    http://github.com/robotlegs/robotlegs-framework/blob/master/src/org...

    You want to add views with autoCreate set to false I bet. You will have to manually create your mediators if you do this.

  3. 3 Posted by Piers on 21 Jan, 2010 01:10 AM

    Piers's Avatar

    Thanks, but I think that's unrelated to the problem. If I turn of autoCreate it'll stop RobotLegs from automatically creating GameMediator to mediate GameController, but as the instance of GameController is still a child of contextView, MediatorMap.onViewAdded() will still get triggered any time a child of GameController is added or created.

    BTW, MediatorMap.onViewAdded() doesn't actually do anything when it's called – because no children I'm adding to GameController have mediators assigned – but the method call itself has an overhead, and when the game is adding and removing a lot of children, I need as little overhead as possible. I think possibly there's no solution to this other than architecting it so that GameController isn't a child of contextView.

  4. Support Staff 4 Posted by Till Schneidere... on 21 Jan, 2010 01:38 PM

    Till Schneidereit's Avatar

    Hi Piers,

    that is a well-known drawback of the way Robotlegs detects new views
    on the display list of its context view. Unfortunately, there doesn't
    seem to be any other way to achieve the auto-mediation functionality.
    At least, nobody came up with one, yet.

    The only "solutions" to your problem that I can think of are:
    - Remove the MediatorMap's ON_ADDED_TO_STAGE handler after your game
    has been initialized. This seems quite radical and pretty restricting
    to me as you wouldn't be able to properly use Robotlegs for any
    additional game UI that gets added later.
    - Create the game stage you don't want to be mediated in a view that's
    not below the contextView in the display list. This might work out
    pretty well depending on whether your design allows for this
    separation.

    hope that helps,
    till

  5. 5 Posted by Piers on 21 Jan, 2010 01:47 PM

    Piers's Avatar

    Thanks Till, second option looks to be the way forward. Shouldn't be a problem to implement.

    Thanks all for such a great framework, it's a joy to use :)

  6. Support Staff 6 Posted by Shaun Smith on 21 Jan, 2010 11:16 PM

    Shaun Smith's Avatar

    It should be mentioned that the MediatorMap can be enabled/disabled. I always imagined that I'd disable it during gameplay and enable it (via a Command for example) during out-of-game states, but I've yet to actually build my game :)

  7. Stray closed this discussion on 13 Feb, 2011 06:42 PM.

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

Keyboard shortcuts

Generic

? 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