Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

This is a plugin for the ImpactJS game engine, design to help you more efficiently manage the various scenes within your game.

branch: master

Static collision now works with scenes.

The collision map was not being copied properly to the global game
reference. This reference to this map is now updated properly.
latest commit 9236374a2f
Sam Green authored July 18, 2012
Octocat-spinner-32 README.md Minor formatting tweaks July 21, 2011
Octocat-spinner-32 main.js Minor formatting tweaks July 21, 2011
Octocat-spinner-32 scene_manager.js Static collision now works with scenes. July 18, 2012
README.md

Scene Management Plugin for ImpactJS

Scene Manager is a plugin for the ImpactJS game engine. This plugin is design to help you more efficiently manage the various scenes within your game. By only drawing and updating the scene on the top of the stack, we are able to remain very performant while still keeping various scenes isolated and modular.

The Basics

Copy the scene_manager.js file into your lib/plugins/ directory and require plugins.scene_manager in your game class. To add a tween to an entity and start it immediately, you would do something like the following:

ParentGame = ig.Game.extend({
    sceneManager: new SceneManager(),

    init: function() {
        // Push the menu scene on to the stack, where MenuScene is a subclass of Scene
        this.sceneManager.pushScene( new MenuScene() );
    },

    update: function() {
        // Update the current scene
        this.sceneManager.updateScene();
    },

    draw: function() {
        // Draw the current scene
        this.sceneManager.drawScene();
    }
});

Usage

These methods will allow you to manage the stack of scenes currently being maintained by the Scene Manager.

Move to a new scene, saving the current scene on the stack:

this.sceneManager.pushScene( newScene );

Move to a new scene and discard the current scene (useful for cutscenes):

this.sceneManager.replaceScene( newScene );

Move to the previous scene:

this.sceneManager.popScene();   

Return to the first scene (useful for main menu):

this.sceneManager.popToRootScene();

Set the stack of scenes to the scenes contained in the array parameters (useful for recreating a previous state):

this.sceneManager.setScenes( [ menuScene, gameScene, optionScene ] );

Scenes

The Scene Manager class also declares a Scene class. This is a subclass of game. You may optionally initialize the scene with a title, in which case the title will be drawn at the center top of the scene using the default font. All scenes provide a method to determine if they are currently being updated and drawn:

myScene.isTopScene() // true, means the current scene is being drawn and updated
Something went wrong with that request. Please try again.