Restart Game - Based on Stray's Idea, Black Screen

thomas.thorstensson's Avatar

thomas.thorstensson

17 Mar, 2012 01:42 PM

Hello Dear Robotleg useers.

Have patience with me on this one as I'm sure the answer is obvious : I seem not to be able to figure out why the excellent solution by Stray for restarting a game using root view doesn't work for me. Instead I get a black background i.e the background color of the swf.

Code:

` public class Application extends Sprite {

    private var _context:ApplicationContext;
    public var  _contextView:Sprite;
    protected const PAUSE_FRAME_COUNT:uint=25;
    protected var frameCount:uint;


    public function Application() {


        createNewContext();
    }

    protected function listenForRestart():void {
        trace("READY");
        _contextView.addEventListener(GameStatusEvent.GAME_RESTARTED, restartHandler);
    }

    protected function restartHandler(e:GameStatusEvent):void {
        removeChild(_contextView);
        _contextView=null;
        _context=null;
        restartAfterPause();
    }

    protected function restartAfterPause():void {
        frameCount=0;
        addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

    protected function enterFrameHandler(e:Event):void {
        frameCount++;
        if (frameCount > PAUSE_FRAME_COUNT) {
            removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
            createNewContext();
        }
    }

    protected function createNewContext():void {
        _contextView=new Sprite();
        addChild(_contextView);
        _context=new ApplicationContext(_contextView);
        listenForRestart();
    }
}

} `

///

Hmm I noticed that my ApplicationContext is no longer firing its startup() method but it was when I was using

 _context=new ApplicationContext(this);

but now I'm using

_context=new ApplicationContext(_contextView)

Hmm is this related to my PrepViewCommand and

        mediatorMap.mapView(Application, ApplicationMediator);
        mediatorMap.createMediator(contextView);

hmmm

OK So I managed to get the startup of ApplicationContext to fire again by just adding

        if (stage) createNewContext()
        else addEventListener(Event.ADDED_TO_STAGE, createNewContext);

But my screen is still blank...

  1. 1 Posted by thomas.thorsten... on 17 Mar, 2012 03:39 PM

    thomas.thorstensson's Avatar

    Oh dear, please bring me some food, this is embarrasing.

    FOUND IT!

    The self solver strikes again. All I needed was of course

            mediatorMap.mapView(Application, ApplicationMediator);  
            mediatorMap.createMediator(contextView.parent);
    

    Grrr!

    Thanks anyhow

  2. Support Staff 2 Posted by Ondina D.F. on 19 Mar, 2012 09:15 AM

    Ondina D.F.'s Avatar

    Hi Thomas,

    Don’t worry about it. It happens to all of us. Sometimes explaining your problem to others makes you see it more clearly and the solution becomes obvious.

    Ondina

  3. Ondina D.F. closed this discussion on 19 Mar, 2012 09:15 AM.

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