Restart Game - Based on Stray's Idea, Black Screen
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...
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
1 Posted by thomas.thorsten... on 17 Mar, 2012 03:39 PM
Oh dear, please bring me some food, this is embarrasing.
FOUND IT!
The self solver strikes again. All I needed was of course
Grrr!
Thanks anyhow
Support Staff 2 Posted by Ondina D.F. on 19 Mar, 2012 09:15 AM
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
Ondina D.F. closed this discussion on 19 Mar, 2012 09:15 AM.