Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/scenemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ function SceneManager(p)
oScene: oScene,
hasSetup : "setup" in oScene,
hasEnter : "enter" in oScene,
hasExit : "exit" in oScene,
hasDraw : "draw" in oScene,
setupExecuted : false,
enterExecuted : false };
enterExecuted : false,
exitExecuted : false };

this.scenes.push(o);
return o;
Expand Down Expand Up @@ -110,13 +112,21 @@ function SceneManager(p)
// Arguments will be retrieved in the scene via .sceneArgs property
this.showScene = function( fnScene, sceneArgs )
{
var currScene = this.scene;
if ( currScene != null && currScene.hasExit && !currScene.exitExecuted )
{
currScene.oScene.exit();
currScene.exitExecuted = true;
}

var o = this.findScene( fnScene );

if ( o == null )
o = this.addScene( fnScene );

// Re-arm the enter function at each show of the scene
o.enterExecuted = false;
o.exitExecuted = false;

this.scene = o;

Expand All @@ -133,12 +143,13 @@ function SceneManager(p)
return;

var nextSceneIndex = 0;
var currScene = this.scene;

if ( this.scene != null )
if ( currScene != null )
{
// search current scene...
// can be optimized to avoid searching current scene...
var i = this.findSceneIndex( this.scene.fnScene );
var i = this.findSceneIndex( currScene.fnScene );
nextSceneIndex = i < this.scenes.length - 1 ? i + 1 : 0;
}

Expand Down Expand Up @@ -177,7 +188,7 @@ function SceneManager(p)
}


// Handle a certain even for a scene...
// Handle a certain event for a scene...
// It is used by the anonymous functions from the wire() function
this.handleEvent = function(sEvent)
{
Expand Down