Renaming from State to Scene internally.

This is one monster update.
This commit is contained in:
photonstorm 2017-07-14 14:30:20 +01:00
parent 8bae761d75
commit d804e056ed
140 changed files with 940 additions and 942 deletions

View file

@ -15,7 +15,7 @@ var Map = require('../../structs/Map');
* *
* Sprites and other Game Objects get the data they need from the AnimationManager. * Sprites and other Game Objects get the data they need from the AnimationManager.
* *
* Access it via `state.anims`. * Access it via `scene.anims`.
* *
* @class Phaser.AnimationManager * @class Phaser.AnimationManager
* @constructor * @constructor

View file

@ -41,7 +41,7 @@ var Config = new Class({
this.canvas = GetValue(config, 'canvas', null); this.canvas = GetValue(config, 'canvas', null);
this.canvasStyle = GetValue(config, 'canvasStyle', null); this.canvasStyle = GetValue(config, 'canvasStyle', null);
this.stateConfig = GetValue(config, 'state', null); this.sceneConfig = GetValue(config, 'scene', null);
this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]); this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);

View file

@ -14,7 +14,7 @@ var CreateRenderer = require('./CreateRenderer');
var Data = require('../plugins/Data'); var Data = require('../plugins/Data');
var GlobalCache = require('../cache/GlobalCache'); var GlobalCache = require('../cache/GlobalCache');
var GlobalInputManager = require('../input/GlobalInputManager'); var GlobalInputManager = require('../input/GlobalInputManager');
var GlobalStateManager = require('../state/GlobalStateManager'); var GlobalSceneManager = require('../scene/GlobalSceneManager');
var TextureManager = require('../textures/TextureManager'); var TextureManager = require('../textures/TextureManager');
var TimeStep = require('./TimeStep'); var TimeStep = require('./TimeStep');
@ -64,9 +64,9 @@ var Game = new Class({
this.input = new GlobalInputManager(this, this.config); this.input = new GlobalInputManager(this, this.config);
/** /**
* @property {Phaser.GlobalStateManager} state - The StateManager. Phaser instance specific. * @property {Phaser.GlobalSceneManager} scene - The SceneManager. Phaser instance specific.
*/ */
this.state = new GlobalStateManager(this, this.config.stateConfig); this.scene = new GlobalSceneManager(this, this.config.sceneConfig);
/** /**
* @property {Phaser.Device} device - Contains device information and capabilities (singleton) * @property {Phaser.Device} device - Contains device information and capabilities (singleton)
@ -100,7 +100,7 @@ var Game = new Class({
this.anims.boot(this.textures); this.anims.boot(this.textures);
this.state.boot(); this.scene.boot();
this.input.boot(); this.input.boot();
@ -120,18 +120,18 @@ var Game = new Class({
step: function (time, delta) step: function (time, delta)
{ {
var active = this.state.active; var active = this.scene.active;
var renderer = this.renderer; var renderer = this.renderer;
// Global Managers (Time, Input, etc) // Global Managers (Time, Input, etc)
this.input.update(time, delta); this.input.update(time, delta);
// States // Scenes
for (var i = 0; i < active.length; i++) for (var i = 0; i < active.length; i++)
{ {
active[i].state.sys.step(time, delta); active[i].scene.sys.step(time, delta);
} }
// Render // Render
@ -140,10 +140,10 @@ var Game = new Class({
renderer.preRender(); renderer.preRender();
// This uses active.length, in case state.update removed the state from the active list // This uses active.length, in case scene.update removed the scene from the active list
for (i = 0; i < active.length; i++) for (i = 0; i < active.length; i++)
{ {
active[i].state.sys.render(0, renderer); active[i].scene.sys.render(0, renderer);
} }
renderer.postRender(); renderer.postRender();
@ -153,11 +153,11 @@ var Game = new Class({
{ {
this.loop.pause(); this.loop.pause();
// var active = this.state.active; // var active = this.scene.active;
// for (var i = 0; i < active.length; i++) // for (var i = 0; i < active.length; i++)
// { // {
// active[i].state.sys.pause(); // active[i].scene.sys.pause();
// } // }
}, },
@ -165,11 +165,11 @@ var Game = new Class({
{ {
this.loop.resume(); this.loop.resume();
// var active = this.state.active; // var active = this.scene.active;
// for (var i = 0; i < active.length; i++) // for (var i = 0; i < active.length; i++)
// { // {
// active[i].state.sys.resume(); // active[i].scene.sys.resume();
// } // }
}, },

View file

@ -171,9 +171,9 @@ var Camera = new Class({
return this; return this;
}, },
setState: function (state) setScene: function (scene)
{ {
this.state = state; this.scene = scene;
return this; return this;
}, },
@ -477,7 +477,7 @@ var Camera = new Class({
destroy: function () destroy: function ()
{ {
this.state = undefined; this.scene = undefined;
} }
}); });

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: '8d1f7160-682b-11e7-b9b9-afea77e03fb0' build: 'de3f9290-689a-11e7-813e-ffb54ad43616'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -2,7 +2,7 @@ var GetAdvancedValue = require('../utils/object/GetAdvancedValue');
var ScaleModes = require('../renderer/ScaleModes'); var ScaleModes = require('../renderer/ScaleModes');
var BlendModes = require('../renderer/BlendModes'); var BlendModes = require('../renderer/BlendModes');
var BuildGameObject = function (state, gameObject, config) var BuildGameObject = function (scene, gameObject, config)
{ {
// Position // Position
@ -89,13 +89,13 @@ var BuildGameObject = function (state, gameObject, config)
gameObject.visible = GetAdvancedValue(config, 'visible', true); gameObject.visible = GetAdvancedValue(config, 'visible', true);
// Add to State // Add to Scene
var add = GetAdvancedValue(config, 'add', true); var add = GetAdvancedValue(config, 'add', true);
if (add) if (add)
{ {
state.children.add(gameObject); scene.sys.displayList.add(gameObject);
} }
return gameObject; return gameObject;

View file

@ -17,9 +17,9 @@ var GameObject = new Class({
initialize: initialize:
function GameObject (state, type) function GameObject (scene, type)
{ {
this.state = state; this.scene = scene;
this.type = type; this.type = type;
@ -39,8 +39,8 @@ var GameObject = new Class({
this.hitArea = null; this.hitArea = null;
this.hitAreaCallback = null; this.hitAreaCallback = null;
// Trigger a state z-depth sort // Trigger a scene z-depth sort
this.state.sys.sortChildrenFlag = true; this.scene.sys.sortChildrenFlag = true;
}, },
// For GameObject Pooling and item selection // For GameObject Pooling and item selection
@ -58,7 +58,7 @@ var GameObject = new Class({
setHitArea: function (shape, callback) setHitArea: function (shape, callback)
{ {
this.state.sys.inputManager.setHitArea(this, shape, callback); this.scene.sys.inputManager.setHitArea(this, shape, callback);
return this; return this;
}, },
@ -73,7 +73,7 @@ var GameObject = new Class({
{ {
this.parent.remove(this); this.parent.remove(this);
this.state = undefined; this.scene = undefined;
} }
}); });

View file

@ -1,15 +1,15 @@
var ParseXMLBitmapFont = require('./ParseXMLBitmapFont'); var ParseXMLBitmapFont = require('./ParseXMLBitmapFont');
var ParseFromAtlas = function (state, fontName, textureKey, frameKey, xmlKey, xSpacing, ySpacing) var ParseFromAtlas = function (scene, fontName, textureKey, frameKey, xmlKey, xSpacing, ySpacing)
{ {
var frame = state.sys.textures.getFrame(textureKey, frameKey); var frame = scene.sys.textures.getFrame(textureKey, frameKey);
var xml = state.sys.cache.xml.get(xmlKey); var xml = scene.sys.cache.xml.get(xmlKey);
if (frame && xml) if (frame && xml)
{ {
var data = ParseXMLBitmapFont(xml, xSpacing, ySpacing, frame); var data = ParseXMLBitmapFont(xml, xSpacing, ySpacing, frame);
state.sys.cache.bitmapFont.add(fontName, { data: data, texture: textureKey, frame: frameKey }); scene.sys.cache.bitmapFont.add(fontName, { data: data, texture: textureKey, frame: frameKey });
return true; return true;
} }

View file

@ -11,7 +11,7 @@ var GetValue = require('../../utils/object/GetValue');
// Phaser.GameObject.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) // Phaser.GameObject.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)
// { // {
// image: key, // image: key,
// width: 32, // width: 32,
// height: 32, // height: 32,
// chars: 'string', // chars: 'string',
@ -20,7 +20,7 @@ var GetValue = require('../../utils/object/GetValue');
// offset: { x: 0, y: 0 } // offset: { x: 0, y: 0 }
// } // }
var ParseRetroFont = function (state, config) var ParseRetroFont = function (scene, config)
{ {
var w = config.width; var w = config.width;
var h = config.height; var h = config.height;
@ -38,7 +38,7 @@ var ParseRetroFont = function (state, config)
if (charsPerRow === null) if (charsPerRow === null)
{ {
charsPerRow = state.sys.textures.getFrame(key).width / w; charsPerRow = scene.sys.textures.getFrame(key).width / w;
if (charsPerRow > letters.length) if (charsPerRow > letters.length)
{ {

View file

@ -22,14 +22,14 @@ var DynamicBitmapText = new Class({
initialize: initialize:
function DynamicBitmapText (state, x, y, font, text, size, align) function DynamicBitmapText (scene, x, y, font, text, size, align)
{ {
if (text === undefined) { text = ''; } if (text === undefined) { text = ''; }
if (align === undefined) { align = 'left'; } if (align === undefined) { align = 'left'; }
GameObject.call(this, state, 'DynamicBitmapText'); GameObject.call(this, scene, 'DynamicBitmapText');
this.fontData = this.state.sys.cache.bitmapFont.get(font); this.fontData = this.scene.sys.cache.bitmapFont.get(font);
this.text = (Array.isArray(text)) ? text.join('\n') : text; this.text = (Array.isArray(text)) ? text.join('\n') : text;

View file

@ -2,16 +2,16 @@ var BitmapText = require('./DynamicBitmapText');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var DynamicBitmapTextCreator = function (state, config) var DynamicBitmapTextCreator = function (scene, config)
{ {
var font = GetAdvancedValue(config, 'font', ''); var font = GetAdvancedValue(config, 'font', '');
var text = GetAdvancedValue(config, 'text', ''); var text = GetAdvancedValue(config, 'text', '');
var size = GetAdvancedValue(config, 'size', false); var size = GetAdvancedValue(config, 'size', false);
var align = GetAdvancedValue(config, 'align', 'left'); var align = GetAdvancedValue(config, 'align', 'left');
var bitmapText = new BitmapText(state, 0, 0, font, text, size, align); var bitmapText = new BitmapText(scene, 0, 0, font, text, size, align);
BuildGameObject(state, bitmapText, config); BuildGameObject(scene, bitmapText, config);
return bitmapText; return bitmapText;
}; };

View file

@ -1,8 +1,8 @@
var BitmapText = require('./DynamicBitmapText'); var BitmapText = require('./DynamicBitmapText');
var DynamicBitmapTextFactory = function (state, x, y, font, text, size, align) var DynamicBitmapTextFactory = function (scene, x, y, font, text, size, align)
{ {
return new BitmapText(state, x, y, font, text, size, align); return new BitmapText(scene, x, y, font, text, size, align);
}; };
module.exports = DynamicBitmapTextFactory; module.exports = DynamicBitmapTextFactory;

View file

@ -25,15 +25,15 @@ var BitmapText = new Class({
initialize: initialize:
function BitmapText (state, x, y, font, text, size) function BitmapText (scene, x, y, font, text, size)
{ {
if (text === undefined) { text = ''; } if (text === undefined) { text = ''; }
GameObject.call(this, state, 'BitmapText'); GameObject.call(this, scene, 'BitmapText');
this.font = font; this.font = font;
var entry = this.state.sys.cache.bitmapFont.get(font); var entry = this.scene.sys.cache.bitmapFont.get(font);
this.fontData = entry.data; this.fontData = entry.data;

View file

@ -3,16 +3,16 @@ var BuildGameObject = require('../../BuildGameObject');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var GetValue = require('../../../utils/object/GetValue'); var GetValue = require('../../../utils/object/GetValue');
var BitmapTextCreator = function (state, config) var BitmapTextCreator = function (scene, config)
{ {
var font = GetValue(config, 'font', ''); var font = GetValue(config, 'font', '');
var text = GetAdvancedValue(config, 'text', ''); var text = GetAdvancedValue(config, 'text', '');
var size = GetAdvancedValue(config, 'size', false); var size = GetAdvancedValue(config, 'size', false);
var align = GetValue(config, 'align', 'left'); // var align = GetValue(config, 'align', 'left');
var bitmapText = new BitmapText(state, 0, 0, font, text, size); var bitmapText = new BitmapText(scene, 0, 0, font, text, size);
BuildGameObject(state, bitmapText, config); BuildGameObject(scene, bitmapText, config);
return bitmapText; return bitmapText;
}; };

View file

@ -1,8 +1,8 @@
var BitmapText = require('./BitmapText'); var BitmapText = require('./BitmapText');
var BitmapTextFactory = function (state, x, y, font, text, size) var BitmapTextFactory = function (scene, x, y, font, text, size)
{ {
return new BitmapText(state, x, y, font, text, size); return new BitmapText(scene, x, y, font, text, size);
}; };
module.exports = BitmapTextFactory; module.exports = BitmapTextFactory;

View file

@ -43,9 +43,9 @@ var Blitter = new Class({
initialize: initialize:
function Blitter (state, x, y, texture, frame) function Blitter (scene, x, y, texture, frame)
{ {
GameObject.call(this, state, 'Blitter'); GameObject.call(this, scene, 'Blitter');
this.setTexture(texture, frame); this.setTexture(texture, frame);
this.setPosition(x, y); this.setPosition(x, y);

View file

@ -2,14 +2,14 @@ var Blitter = require('./Blitter');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var BlitterCreator = function (state, config) var BlitterCreator = function (scene, config)
{ {
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null); var frame = GetAdvancedValue(config, 'frame', null);
var blitter = new Blitter(state, 0, 0, key, frame); var blitter = new Blitter(scene, 0, 0, key, frame);
BuildGameObject(state, blitter, config); BuildGameObject(scene, blitter, config);
return blitter; return blitter;
}; };

View file

@ -1,8 +1,8 @@
var Blitter = require('./Blitter'); var Blitter = require('./Blitter');
var BlitterFactory = function (state, x, y, key, frame) var BlitterFactory = function (scene, x, y, key, frame)
{ {
return new Blitter(state, x, y, key, frame); return new Blitter(scene, x, y, key, frame);
}; };
module.exports = BlitterFactory; module.exports = BlitterFactory;

View file

@ -13,7 +13,7 @@ var Animation = new Class({
// Sprite / Game Object // Sprite / Game Object
this.parent = parent; this.parent = parent;
this.animationManager = parent.state.sys.anims; this.animationManager = parent.scene.sys.anims;
this.animationManager.events.once('REMOVE_ANIMATION_EVENT', this.remove.bind(this)); this.animationManager.events.once('REMOVE_ANIMATION_EVENT', this.remove.bind(this));

View file

@ -10,7 +10,7 @@ var Texture = {
setTexture: function (key, frame) setTexture: function (key, frame)
{ {
this.texture = this.state.sys.textures.get(key); this.texture = this.scene.sys.textures.get(key);
this.frame = this.texture.get(frame); this.frame = this.texture.get(frame);

View file

@ -29,7 +29,7 @@ var Transform = {
set: function (value) set: function (value)
{ {
this.state.sys.sortChildrenFlag = true; this.scene.sys.sortChildrenFlag = true;
this._z = value; this._z = value;
} }

View file

@ -29,12 +29,12 @@ var EffectLayer = new Class({
initialize: initialize:
function EffectLayer (state, x, y, width, height, effectName, fragmentShader) function EffectLayer (scene, x, y, width, height, effectName, fragmentShader)
{ {
GameObject.call(this, state, 'EffectLayer'); GameObject.call(this, scene, 'EffectLayer');
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0); var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
var resourceManager = state.game.renderer.resourceManager; var resourceManager = scene.game.renderer.resourceManager;
var wrap; var wrap;
var gl; var gl;
@ -45,7 +45,7 @@ var EffectLayer = new Class({
if (resourceManager !== undefined) if (resourceManager !== undefined)
{ {
gl = state.game.renderer.gl; gl = scene.game.renderer.gl;
wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
this.dstShader = resourceManager.createShader(effectName, { this.dstShader = resourceManager.createShader(effectName, {
vert: TexturedAndNormalizedTintedShader.vert, vert: TexturedAndNormalizedTintedShader.vert,
@ -61,7 +61,7 @@ var EffectLayer = new Class({
); );
this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null); this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null);
state.game.renderer.currentTexture = null; // force rebinding of prev texture scene.game.renderer.currentTexture = null; // force rebinding of prev texture
} }
this.flipY = true; this.flipY = true;

View file

@ -2,7 +2,7 @@ var EffectLayer = require('./EffectLayer');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var EffectLayerCreator = function (state, config) var EffectLayerCreator = function (scene, config)
{ {
var x = GetAdvancedValue(config, 'x', 0); var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0); var y = GetAdvancedValue(config, 'y', 0);
@ -11,9 +11,9 @@ var EffectLayerCreator = function (state, config)
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var fragmentShader = GetAdvancedValue(config, 'fragmentShader', ''); var fragmentShader = GetAdvancedValue(config, 'fragmentShader', '');
var layer = new EffectLayer(state, x, y, width, height, effectName, fragmentShader); var layer = new EffectLayer(scene, x, y, width, height, effectName, fragmentShader);
BuildGameObject(state, layer, config); BuildGameObject(scene, layer, config);
return layer; return layer;
}; };

View file

@ -1,8 +1,8 @@
var EffectLayer = require('./EffectLayer'); var EffectLayer = require('./EffectLayer');
var EffectLayerFactory = function (state, x, y, width, height, effectName, fragmentShader) var EffectLayerFactory = function (scene, x, y, width, height, effectName, fragmentShader)
{ {
return new EffectLayer(state, x, y, width, height, effectName, fragmentShader); return new EffectLayer(scene, x, y, width, height, effectName, fragmentShader);
}; };
module.exports = EffectLayerFactory; module.exports = EffectLayerFactory;

View file

@ -24,12 +24,12 @@ var Graphics = new Class({
initialize: initialize:
function Graphics (state, options) function Graphics (scene, options)
{ {
var x = GetValue(options, 'x', 0); var x = GetValue(options, 'x', 0);
var y = GetValue(options, 'y', 0); var y = GetValue(options, 'y', 0);
GameObject.call(this, state, 'Graphics'); GameObject.call(this, scene, 'Graphics');
this.setPosition(x, y); this.setPosition(x, y);
@ -44,12 +44,12 @@ var Graphics = new Class({
this.setDefaultStyles(options); this.setDefaultStyles(options);
var resourceManager = state.game.renderer.resourceManager; var resourceManager = scene.game.renderer.resourceManager;
if (resourceManager !== undefined) if (resourceManager !== undefined)
{ {
this.resourceManager = resourceManager; this.resourceManager = resourceManager;
this.gl = state.game.renderer.gl; this.gl = scene.game.renderer.gl;
} }
}, },
@ -383,8 +383,8 @@ var Graphics = new Class({
generateTexture: function (key, width, height) generateTexture: function (key, width, height)
{ {
var screenWidth = this.state.game.config.width; var screenWidth = this.scene.game.config.width;
var screenHeight = this.state.game.config.height; var screenHeight = this.scene.game.config.height;
width = (typeof width === 'number') ? width : screenWidth; width = (typeof width === 'number') ? width : screenWidth;
height = (typeof height === 'number') ? height : screenHeight; height = (typeof height === 'number') ? height : screenHeight;
@ -392,13 +392,13 @@ var Graphics = new Class({
Graphics.TargetCamera.scrollX = this.x; Graphics.TargetCamera.scrollX = this.x;
Graphics.TargetCamera.scrollY = this.y; Graphics.TargetCamera.scrollY = this.y;
var texture = this.state.game.textures.createCanvas(key, width, height); var texture = this.scene.game.textures.createCanvas(key, width, height);
var ctx = texture.source[0].image.getContext('2d'); var ctx = texture.source[0].image.getContext('2d');
texture.add('__BASE', 0, 0, 0, width, height); texture.add('__BASE', 0, 0, 0, width, height);
this.renderCanvas(this.state.game.renderer, this, 0, Graphics.TargetCamera, ctx); this.renderCanvas(this.scene.game.renderer, this, 0, Graphics.TargetCamera, ctx);
if (this.gl) if (this.gl)
{ {
this.state.game.renderer.uploadCanvasToGPU(ctx.canvas, texture.source[0].glTexture, true); this.scene.game.renderer.uploadCanvasToGPU(ctx.canvas, texture.source[0].glTexture, true);
} }
} }

View file

@ -1,10 +1,8 @@
var Graphics = require('./Graphics'); var Graphics = require('./Graphics');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject');
var GraphicsCreator = function (state, config) var GraphicsCreator = function (scene, config)
{ {
return new Graphics(state, config); return new Graphics(scene, config);
}; };
module.exports = GraphicsCreator; module.exports = GraphicsCreator;

View file

@ -1,8 +1,8 @@
var Graphics = require('./Graphics'); var Graphics = require('./Graphics');
var GraphicsFactory = function (state, config) var GraphicsFactory = function (scene, config)
{ {
return new Graphics(state, config); return new Graphics(scene, config);
}; };
module.exports = GraphicsFactory; module.exports = GraphicsFactory;

View file

@ -10,9 +10,9 @@ var Group = new Class({
initialize: initialize:
function Group (state, children, config) function Group (scene, children, config)
{ {
this.state = state; this.scene = scene;
this.children = new Set(children); this.children = new Set(children);
@ -64,13 +64,13 @@ var Group = new Class({
{ {
if (visible === undefined) { visible = true; } if (visible === undefined) { visible = true; }
var child = new this.classType(this.state, x, y, key, frame); var child = new this.classType(this.scene, x, y, key, frame);
this.state.sys.displayList.add(child); this.scene.sys.displayList.add(child);
if (child.preUpdate) if (child.preUpdate)
{ {
this.state.sys.updateList.add(child); this.scene.sys.updateList.add(child);
} }
child.visible = visible; child.visible = visible;
@ -229,7 +229,7 @@ var Group = new Class({
{ {
this.children.clear(); this.children.clear();
this.state = undefined; this.scene = undefined;
this.children = undefined; this.children = undefined;
}, },

View file

@ -1,8 +1,8 @@
var Group = require('./Group'); var Group = require('./Group');
var GroupCreator = function (state, config) var GroupCreator = function (scene, config)
{ {
return new Group(state, null, config); return new Group(scene, null, config);
}; };
module.exports = GroupCreator; module.exports = GroupCreator;

View file

@ -1,8 +1,8 @@
var Group = require('./Group'); var Group = require('./Group');
var GroupFactory = function (state, children, config) var GroupFactory = function (scene, children, config)
{ {
return new Group(state, children, config); return new Group(scene, children, config);
}; };
module.exports = GroupFactory; module.exports = GroupFactory;

View file

@ -27,9 +27,9 @@ var Image = new Class({
initialize: initialize:
function Image (state, x, y, texture, frame) function Image (scene, x, y, texture, frame)
{ {
GameObject.call(this, state, 'Image'); GameObject.call(this, scene, 'Image');
this.setTexture(texture, frame); this.setTexture(texture, frame);
this.setPosition(x, y); this.setPosition(x, y);

View file

@ -2,14 +2,14 @@ var Image = require('./Image');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var ImageCreator = function (state, config) var ImageCreator = function (scene, config)
{ {
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null); var frame = GetAdvancedValue(config, 'frame', null);
var image = new Image(state, 0, 0, key, frame); var image = new Image(scene, 0, 0, key, frame);
BuildGameObject(state, image, config); BuildGameObject(scene, image, config);
return image; return image;
}; };

View file

@ -1,8 +1,8 @@
var Image = require('./Image'); var Image = require('./Image');
var ImageFactory = function (state, x, y, key, frame) var ImageFactory = function (scene, x, y, key, frame)
{ {
return new Image(state, x, y, key, frame); return new Image(scene, x, y, key, frame);
}; };
module.exports = ImageFactory; module.exports = ImageFactory;

View file

@ -26,9 +26,9 @@ var Mesh = new Class({
initialize: initialize:
function Mesh (state, x, y, vertices, uv, indices, colors, alphas, texture, frame) function Mesh (scene, x, y, vertices, uv, indices, colors, alphas, texture, frame)
{ {
GameObject.call(this, state, 'Mesh'); GameObject.call(this, scene, 'Mesh');
this.setTexture(texture, frame); this.setTexture(texture, frame);
this.setPosition(x, y); this.setPosition(x, y);

View file

@ -3,7 +3,7 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var GetValue = require('../../utils/object/GetValue'); var GetValue = require('../../utils/object/GetValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var MeshCreator = function (state, config) var MeshCreator = function (scene, config)
{ {
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null); var frame = GetAdvancedValue(config, 'frame', null);
@ -13,9 +13,9 @@ var MeshCreator = function (state, config)
var alphas = GetValue(config, 'alphas', []); var alphas = GetValue(config, 'alphas', []);
var uv = GetValue(config, 'uv', []); var uv = GetValue(config, 'uv', []);
var mesh = new Mesh(state, 0, 0, vertices, uv, indices, colors, alphas, key, frame); var mesh = new Mesh(scene, 0, 0, vertices, uv, indices, colors, alphas, key, frame);
BuildGameObject(state, mesh, config); BuildGameObject(scene, mesh, config);
return mesh; return mesh;
}; };

View file

@ -1,8 +1,8 @@
var Mesh = require('./Mesh'); var Mesh = require('./Mesh');
var MeshFactory = function (state, x, y, vertices, uv, key, frame) var MeshFactory = function (scene, x, y, vertices, uv, key, frame)
{ {
return new Mesh(state, x, y, vertices, uv, key, frame); return new Mesh(scene, x, y, vertices, uv, key, frame);
}; };
module.exports = MeshFactory; module.exports = MeshFactory;

View file

@ -15,10 +15,10 @@ var ObjectPool = new Class({
if (callbackScope === undefined) { callbackScope = this; } if (callbackScope === undefined) { callbackScope = this; }
this.manager = manager; this.manager = manager;
this.state = manager.state; this.scene = manager.scene;
this.displayList = this.state.sys.displayList; this.displayList = this.scene.sys.displayList;
this.updateList = this.state.sys.updateList; this.updateList = this.scene.sys.updateList;
this.createCallback = createCallback; this.createCallback = createCallback;
this.callbackScope = callbackScope; this.callbackScope = callbackScope;
@ -32,7 +32,7 @@ var ObjectPool = new Class({
makeGameObject: function () makeGameObject: function ()
{ {
var gameObject = new this.classType(this.state); var gameObject = new this.classType(this.scene);
this.displayList.add(gameObject); this.displayList.add(gameObject);
@ -215,7 +215,7 @@ var ObjectPool = new Class({
destroy: function () destroy: function ()
{ {
this.manager = undefined; this.manager = undefined;
this.state = undefined; this.scene = undefined;
this.displayList = undefined; this.displayList = undefined;
this.updateList = undefined; this.updateList = undefined;

View file

@ -23,7 +23,7 @@ var SpritePool = new Class({
makeSprite: function () makeSprite: function ()
{ {
var gameObject = new this.classType(this.state, 0, 0, this.defaultKey, this.defaultFrame); var gameObject = new this.classType(this.scene, 0, 0, this.defaultKey, this.defaultFrame);
this.displayList.add(gameObject); this.displayList.add(gameObject);
this.updateList.add(gameObject); this.updateList.add(gameObject);

View file

@ -8,7 +8,7 @@ var Quad = new Class({
initialize: initialize:
function Quad (state, x, y, texture, frame) function Quad (scene, x, y, texture, frame)
{ {
// 0----3 // 0----3
// |\ B| // |\ B|
@ -25,7 +25,7 @@ var Quad = new Class({
var colors = [ 0xffffff, 0xffffff, 0xffffff, 0xffffff ]; var colors = [ 0xffffff, 0xffffff, 0xffffff, 0xffffff ];
var alphas = [ 1, 1, 1, 1 ]; var alphas = [ 1, 1, 1, 1 ];
Mesh.call(this, state, x, y, vertices, uv, indices, colors, alphas, texture, frame); Mesh.call(this, scene, x, y, vertices, uv, indices, colors, alphas, texture, frame);
this.resetPosition(); this.resetPosition();
}, },

View file

@ -2,16 +2,16 @@ var Quad = require('./Quad');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var QuadCreator = function (state, config) var QuadCreator = function (scene, config)
{ {
var x = GetAdvancedValue(config, 'x', 0); var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0); var y = GetAdvancedValue(config, 'y', 0);
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null); var frame = GetAdvancedValue(config, 'frame', null);
var quad = new Quad(state, x, y, key, frame); var quad = new Quad(scene, x, y, key, frame);
BuildGameObject(state, quad, config); BuildGameObject(scene, quad, config);
return quad; return quad;
}; };

View file

@ -1,8 +1,8 @@
var Quad = require('./Quad'); var Quad = require('./Quad');
var QuadFactory = function (state, x, y, key, frame) var QuadFactory = function (scene, x, y, key, frame)
{ {
return new Quad(state, x, y, key, frame); return new Quad(scene, x, y, key, frame);
}; };
module.exports = QuadFactory; module.exports = QuadFactory;

View file

@ -33,16 +33,16 @@ var RenderPass = new Class({
initialize: initialize:
function RenderPass (state, x, y, width, height, shaderName, fragmentShader) function RenderPass (scene, x, y, width, height, shaderName, fragmentShader)
{ {
GameObject.call(this, state, 'RenderPass'); GameObject.call(this, scene, 'RenderPass');
var resourceManager = state.game.renderer.resourceManager; var resourceManager = scene.game.renderer.resourceManager;
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0); var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
var gl; var gl;
var wrap; var wrap;
this.renderer = state.game.renderer; this.renderer = scene.game.renderer;
this.passRenderTarget = null; this.passRenderTarget = null;
this.renderTexture = null; this.renderTexture = null;
this.passShader = null; this.passShader = null;
@ -51,12 +51,12 @@ var RenderPass = new Class({
if (resourceManager !== undefined) if (resourceManager !== undefined)
{ {
gl = state.game.renderer.gl; gl = scene.game.renderer.gl;
wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
this.passShader = resourceManager.createShader(shaderName, {vert: TexturedAndNormalizedTintedShader.vert, frag: fragmentShader}); this.passShader = resourceManager.createShader(shaderName, {vert: TexturedAndNormalizedTintedShader.vert, frag: fragmentShader});
this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, wrap, wrap, gl.RGBA, null, width, height); this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, wrap, wrap, gl.RGBA, null, width, height);
this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null); this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null);
state.game.renderer.currentTexture = null; // force rebinding of prev texture scene.game.renderer.currentTexture = null; // force rebinding of prev texture
} }
this.flipY = true; this.flipY = true;

View file

@ -2,7 +2,7 @@ var RenderPass = require('./RenderPass');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var RenderPassCreator = function (state, config) var RenderPassCreator = function (scene, config)
{ {
var x = GetAdvancedValue(config, 'x', 0); var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0); var y = GetAdvancedValue(config, 'y', 0);
@ -11,9 +11,9 @@ var RenderPassCreator = function (state, config)
var shaderName = GetAdvancedValue(config, 'shaderName', ''); var shaderName = GetAdvancedValue(config, 'shaderName', '');
var fragmentShader = GetAdvancedValue(config, 'fragmentShader', ''); var fragmentShader = GetAdvancedValue(config, 'fragmentShader', '');
var pass = new RenderPass(state, x, y, width, height, shaderName, fragmentShader); var pass = new RenderPass(scene, x, y, width, height, shaderName, fragmentShader);
BuildGameObject(state, pass, config); BuildGameObject(scene, pass, config);
return pass; return pass;
}; };

View file

@ -1,8 +1,8 @@
var RenderPass = require('./RenderPass'); var RenderPass = require('./RenderPass');
var RenderPassFactory = function (state, x, y, width, height, shaderName, fragmentShader) var RenderPassFactory = function (scene, x, y, width, height, shaderName, fragmentShader)
{ {
return new RenderPass(state, x, y, width, height, shaderName, fragmentShader); return new RenderPass(scene, x, y, width, height, shaderName, fragmentShader);
}; };
module.exports = RenderPassFactory; module.exports = RenderPassFactory;

View file

@ -27,9 +27,9 @@ var Sprite = new Class({
initialize: initialize:
function Sprite (state, x, y, texture, frame) function Sprite (scene, x, y, texture, frame)
{ {
GameObject.call(this, state, 'Sprite'); GameObject.call(this, scene, 'Sprite');
this.anims = new Components.Animation(this); this.anims = new Components.Animation(this);

View file

@ -3,14 +3,14 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var SpriteCreator = function (state, config) var SpriteCreator = function (scene, config)
{ {
var key = GetAdvancedValue(config, 'key', null); var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null); var frame = GetAdvancedValue(config, 'frame', null);
var sprite = new Sprite(state, 0, 0, key, frame); var sprite = new Sprite(scene, 0, 0, key, frame);
BuildGameObject(state, sprite, config); BuildGameObject(scene, sprite, config);
// Sprite specific config options: // Sprite specific config options:

View file

@ -1,8 +1,8 @@
var Sprite = require('./Sprite'); var Sprite = require('./Sprite');
var SpriteFactory = function (state, x, y, key, frame) var SpriteFactory = function (scene, x, y, key, frame)
{ {
return new Sprite(state, x, y, key, frame); return new Sprite(scene, x, y, key, frame);
}; };
module.exports = SpriteFactory; module.exports = SpriteFactory;

View file

@ -28,13 +28,13 @@ var Text = new Class({
initialize: initialize:
function Text (state, x, y, text, style) function Text (scene, x, y, text, style)
{ {
if (x === undefined) { x = 0; } if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; } if (y === undefined) { y = 0; }
if (text === undefined) { text = ''; } if (text === undefined) { text = ''; }
GameObject.call(this, state, 'Text'); GameObject.call(this, scene, 'Text');
this.setPosition(x, y); this.setPosition(x, y);
this.setOrigin(0, 0); this.setOrigin(0, 0);

View file

@ -2,7 +2,7 @@ var Text = require('./Text');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var TextCreator = function (state, config) var TextCreator = function (scene, config)
{ {
// style Object = { // style Object = {
// font: [ 'font', '16px Courier' ], // font: [ 'font', '16px Courier' ],
@ -26,9 +26,9 @@ var TextCreator = function (state, config)
var content = GetAdvancedValue(config, 'text', ''); var content = GetAdvancedValue(config, 'text', '');
var style = GetAdvancedValue(config, 'style', null); var style = GetAdvancedValue(config, 'style', null);
var text = new Text(state, 0, 0, content, style); var text = new Text(scene, 0, 0, content, style);
BuildGameObject(state, text, config); BuildGameObject(scene, text, config);
// Text specific config options: // Text specific config options:

View file

@ -1,8 +1,8 @@
var Text = require('./Text'); var Text = require('./Text');
var TextFactory = function (state, x, y, text, style) var TextFactory = function (scene, x, y, text, style)
{ {
return new Text(state, x, y, text, style); return new Text(scene, x, y, text, style);
}; };
module.exports = TextFactory; module.exports = TextFactory;

View file

@ -27,9 +27,9 @@ var Tilemap = new Class({
initialize: initialize:
function Tilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) function Tilemap (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
GameObject.call(this, state, 'Tilemap'); GameObject.call(this, scene, 'Tilemap');
this.mapData = mapData !== null ? new Uint32Array(mapData) : new Uint32Array(mapWidth * mapHeight); this.mapData = mapData !== null ? new Uint32Array(mapData) : new Uint32Array(mapWidth * mapHeight);
this.tileWidth = tileWidth; this.tileWidth = tileWidth;

View file

@ -2,7 +2,7 @@ var Tilemap = require('./Tilemap');
var GetValue = require('../../../utils/object/GetValue'); var GetValue = require('../../../utils/object/GetValue');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var TilemapCreator = function (state, config) var TilemapCreator = function (scene, config)
{ {
var mapData = GetValue(config, 'map.data', null); var mapData = GetValue(config, 'map.data', null);
var mapWidth = GetValue(config, 'map.width', 1); var mapWidth = GetValue(config, 'map.width', 1);
@ -17,9 +17,9 @@ var TilemapCreator = function (state, config)
var tileFrame = GetValue(config, 'tile.frame', null); var tileFrame = GetValue(config, 'tile.frame', null);
var tileBorder = GetValue(config, 'tile.border', 0); var tileBorder = GetValue(config, 'tile.border', 0);
var map = new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); var map = new Tilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame);
BuildGameObject(state, map, config); BuildGameObject(scene, map, config);
return map; return map;
}; };

View file

@ -1,9 +1,9 @@
var Tilemap = require('./Tilemap'); var Tilemap = require('./Tilemap');
var TilemapFactory = function (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) var TilemapFactory = function (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
return new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); return new Tilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame);
}; };
module.exports = TilemapFactory; module.exports = TilemapFactory;

View file

@ -27,14 +27,14 @@ var StaticTilemap = new Class({
initialize: initialize:
function StaticTilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) function StaticTilemap (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
GameObject.call(this, state, 'StaticTilemap'); GameObject.call(this, scene, 'StaticTilemap');
this.vbo = null; this.vbo = null;
this.gl = state.game.renderer.gl ? state.game.renderer.gl : null; this.gl = scene.game.renderer.gl ? scene.game.renderer.gl : null;
this.tilemapRenderer = state.game.renderer.tilemapRenderer ? state.game.renderer.tilemapRenderer : null; this.tilemapRenderer = scene.game.renderer.tilemapRenderer ? scene.game.renderer.tilemapRenderer : null;
this.resourceManager = this.gl ? state.game.renderer.resourceManager : null; this.resourceManager = this.gl ? scene.game.renderer.resourceManager : null;
this.bufferData = null; this.bufferData = null;
this.mapData = mapData; this.mapData = mapData;
this.tileWidth = tileWidth; this.tileWidth = tileWidth;

View file

@ -2,7 +2,7 @@ var StaticTilemap = require('./StaticTilemap');
var GetValue = require('../../../utils/object/GetValue'); var GetValue = require('../../../utils/object/GetValue');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var StaticTilemapCreator = function (state, config) var StaticTilemapCreator = function (scene, config)
{ {
var mapData = GetValue(config, 'map.data', null); var mapData = GetValue(config, 'map.data', null);
var mapWidth = GetValue(config, 'map.width', 1); var mapWidth = GetValue(config, 'map.width', 1);
@ -17,9 +17,9 @@ var StaticTilemapCreator = function (state, config)
var tileFrame = GetValue(config, 'tile.frame', null); var tileFrame = GetValue(config, 'tile.frame', null);
var tileBorder = GetValue(config, 'tile.border', 0); var tileBorder = GetValue(config, 'tile.border', 0);
var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); var map = new StaticTilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame);
BuildGameObject(state, map, config); BuildGameObject(scene, map, config);
return map; return map;
}; };

View file

@ -1,8 +1,8 @@
var StaticTilemap = require('./StaticTilemap'); var StaticTilemap = require('./StaticTilemap');
var StaticTilemapFactory = function (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) var StaticTilemapFactory = function (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
return new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); return new StaticTilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame);
}; };
module.exports = StaticTilemapFactory; module.exports = StaticTilemapFactory;

View file

@ -28,11 +28,11 @@ var TileSprite = new Class({
initialize: initialize:
function TileSprite (state, x, y, width, height, texture, frame) function TileSprite (scene, x, y, width, height, texture, frame)
{ {
var resourceManager = state.game.renderer.resourceManager; var resourceManager = scene.game.renderer.resourceManager;
GameObject.call(this, state, 'TileSprite'); GameObject.call(this, scene, 'TileSprite');
this.tilePositionX = 0; this.tilePositionX = 0;
this.tilePositionY = 0; this.tilePositionY = 0;
@ -68,8 +68,8 @@ var TileSprite = new Class({
this.potHeight |= this.potHeight >> 16; this.potHeight |= this.potHeight >> 16;
this.potHeight++; this.potHeight++;
this.renderer = state.game.renderer; this.renderer = scene.game.renderer;
var gl = state.game.renderer.gl; var gl = scene.game.renderer.gl;
this.tileTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.canvasBuffer, this.potWidth, this.potHeight); this.tileTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.canvasBuffer, this.potWidth, this.potHeight);
} }

View file

@ -2,7 +2,7 @@ var TileSprite = require('./TileSprite');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var TileSpriteCreator = function (state, config) var TileSpriteCreator = function (scene, config)
{ {
var x = GetAdvancedValue(config, 'x', 0); var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0); var y = GetAdvancedValue(config, 'y', 0);
@ -11,9 +11,9 @@ var TileSpriteCreator = function (state, config)
var key = GetAdvancedValue(config, 'key', ''); var key = GetAdvancedValue(config, 'key', '');
var frame = GetAdvancedValue(config, 'frame', ''); var frame = GetAdvancedValue(config, 'frame', '');
var tile = new TileSprite(state, x, y, width, height, key, frame); var tile = new TileSprite(scene, x, y, width, height, key, frame);
BuildGameObject(state, tile, config); BuildGameObject(scene, tile, config);
return tile; return tile;
}; };

View file

@ -1,8 +1,8 @@
var TileSprite = require('./TileSprite'); var TileSprite = require('./TileSprite');
var TileSpriteFactory = function (state, x, y, width, height, key, frame) var TileSpriteFactory = function (scene, x, y, width, height, key, frame)
{ {
return new TileSprite(state, x, y, width, height, key, frame); return new TileSprite(scene, x, y, width, height, key, frame);
}; };
module.exports = TileSpriteFactory; module.exports = TileSpriteFactory;

View file

@ -19,9 +19,9 @@ var Zone = new Class({
initialize: initialize:
function Zone (state, x, y, width, height) function Zone (scene, x, y, width, height)
{ {
GameObject.call(this, state, 'Zone'); GameObject.call(this, scene, 'Zone');
this.setPosition(x, y); this.setPosition(x, y);
this.setSize(width, height); this.setSize(width, height);

View file

@ -7,12 +7,12 @@ var ZoneFactory = {
add: function (x, y, width, height) add: function (x, y, width, height)
{ {
return new Zone(this.state, x, y, width, height); return new Zone(this.scene, x, y, width, height);
}, },
make: function (x, y, width, height) make: function (x, y, width, height)
{ {
return new Zone(this.state, x, y, width, height); return new Zone(this.scene, x, y, width, height);
} }
}; };

View file

@ -24,7 +24,7 @@ var BaseLoader = new Class({
this.baseURL = ''; this.baseURL = '';
this.path = ''; this.path = '';
// Read from Game / State Config // Read from Game / Scene Config
this.enableParallel = true; this.enableParallel = true;
this.maxParallelDownloads = 4; this.maxParallelDownloads = 4;
@ -39,7 +39,7 @@ var BaseLoader = new Class({
this.queue = new Set(); this.queue = new Set();
this.storage = new Set(); this.storage = new Set();
this._state = CONST.LOADER_IDLE; this.state = CONST.LOADER_IDLE;
}, },
addFile: function (file) addFile: function (file)
@ -59,18 +59,18 @@ var BaseLoader = new Class({
// Is the Loader actively loading (or processing loaded files) // Is the Loader actively loading (or processing loaded files)
isLoading: function () isLoading: function ()
{ {
return (this._state === CONST.LOADER_LOADING || this._state === CONST.LOADER_PROCESSING); return (this.state === CONST.LOADER_LOADING || this.state === CONST.LOADER_PROCESSING);
}, },
// Is the Loader ready to start a new load? // Is the Loader ready to start a new load?
isReady: function () isReady: function ()
{ {
return (this._state === CONST.LOADER_IDLE || this._state === CONST.LOADER_COMPLETE || this._state === CONST.LOADER_FAILED); return (this.state === CONST.LOADER_IDLE || this.state === CONST.LOADER_COMPLETE || this.state === CONST.LOADER_FAILED);
}, },
start: function () start: function ()
{ {
console.log(this.state.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size); console.log(this.scene.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size);
if (!this.isReady()) if (!this.isReady())
{ {
@ -85,7 +85,7 @@ var BaseLoader = new Class({
} }
else else
{ {
this._state = CONST.LOADER_LOADING; this.state = CONST.LOADER_LOADING;
this.failed.clear(); this.failed.clear();
this.inflight.clear(); this.inflight.clear();
@ -180,7 +180,7 @@ var BaseLoader = new Class({
{ {
// console.log('---> BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files'); // console.log('---> BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files');
this._state = CONST.LOADER_PROCESSING; this.state = CONST.LOADER_PROCESSING;
this.storage.clear(); this.storage.clear();
@ -241,7 +241,7 @@ var BaseLoader = new Class({
{ {
this.queue.delete(file); this.queue.delete(file);
if (this.queue.size === 0 && this._state === CONST.LOADER_PROCESSING) if (this.queue.size === 0 && this.state === CONST.LOADER_PROCESSING)
{ {
// We've processed all the files we loaded // We've processed all the files we loaded
this.processComplete(); this.processComplete();
@ -250,7 +250,7 @@ var BaseLoader = new Class({
processComplete: function () processComplete: function ()
{ {
console.log(this.state.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size); console.log(this.scene.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
this.list.clear(); this.list.clear();
this.inflight.clear(); this.inflight.clear();
@ -261,7 +261,7 @@ var BaseLoader = new Class({
this.processCallback(); this.processCallback();
} }
this._state = CONST.LOADER_COMPLETE; this.state = CONST.LOADER_COMPLETE;
this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this)); this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this));
}, },
@ -281,13 +281,13 @@ var BaseLoader = new Class({
this.path = ''; this.path = '';
this.baseURL = ''; this.baseURL = '';
this._state = CONST.LOADER_IDLE; this.state = CONST.LOADER_IDLE;
}, },
destroy: function () destroy: function ()
{ {
this.reset(); this.reset();
this._state = CONST.LOADER_DESTROYED; this.state = CONST.LOADER_DESTROYED;
} }
}); });

View file

@ -28,7 +28,7 @@ var Phaser = {
GameObjects: require('./gameobjects'), GameObjects: require('./gameobjects'),
State: require('./state/State'), Scene: require('./scene/Scene'),
Loader: { Loader: {

View file

@ -8,18 +8,18 @@ var CameraManager = new Class({
initialize: initialize:
function CameraManager (state) function CameraManager (scene)
{ {
// The State that owns this plugin // The Scene that owns this plugin
this.state = state; this.scene = scene;
this.cameras = []; this.cameras = [];
this.cameraPool = []; this.cameraPool = [];
if (state.sys.settings.cameras) if (scene.sys.settings.cameras)
{ {
// We have cameras to create // We have cameras to create
this.fromJSON(state.sys.settings.cameras); this.fromJSON(scene.sys.settings.cameras);
} }
else else
{ {
@ -64,8 +64,8 @@ var CameraManager = new Class({
config = [ config ]; config = [ config ];
} }
var gameWidth = this.state.sys.game.config.width; var gameWidth = this.scene.sys.game.config.width;
var gameHeight = this.state.sys.game.config.height; var gameHeight = this.scene.sys.game.config.height;
for (var i = 0; i < config.length; i++) for (var i = 0; i < config.length; i++)
{ {
@ -117,8 +117,8 @@ var CameraManager = new Class({
{ {
if (x === undefined) { x = 0; } if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; } if (y === undefined) { y = 0; }
if (width === undefined) { width = this.state.sys.game.config.width; } if (width === undefined) { width = this.scene.sys.game.config.width; }
if (height === undefined) { height = this.state.sys.game.config.height; } if (height === undefined) { height = this.scene.sys.game.config.height; }
var camera = null; var camera = null;
@ -132,7 +132,7 @@ var CameraManager = new Class({
camera = new Camera(x, y, width, height); camera = new Camera(x, y, width, height);
} }
camera.setState(this.state); camera.setScene(this.scene);
this.cameras.push(camera); this.cameras.push(camera);
@ -203,7 +203,7 @@ var CameraManager = new Class({
camera.preRender(); camera.preRender();
renderer.render(this.state, children, interpolation, camera); renderer.render(this.scene, children, interpolation, camera);
} }
}, },
@ -223,7 +223,7 @@ var CameraManager = new Class({
this.cameras = []; this.cameras = [];
this.cameraPool = []; this.cameraPool = [];
this.state = undefined; this.scene = undefined;
} }
}); });

View file

@ -4,10 +4,10 @@ var DisplayList = new Class({
initialize: initialize:
function DisplayList (state) function DisplayList (scene)
{ {
// The State that owns this plugin // The Scene that owns this plugin
this.state = state; this.scene = scene;
// The objects that belong to this collection. // The objects that belong to this collection.
// The equivalent of the old `Sprite.children` array. // The equivalent of the old `Sprite.children` array.
@ -18,7 +18,7 @@ var DisplayList = new Class({
add: function (child) add: function (child)
{ {
if (child.parent === this.state) if (child.parent === this.scene)
{ {
return child; return child;
} }
@ -27,7 +27,7 @@ var DisplayList = new Class({
child.parent.children.remove(child); child.parent.children.remove(child);
} }
child.parent = this.state; child.parent = this.scene;
this.list.push(child); this.list.push(child);
@ -50,7 +50,7 @@ var DisplayList = new Class({
child.parent.children.remove(child); child.parent.children.remove(child);
} }
child.parent = this.state; child.parent = this.scene;
this.list.splice(index, 0, child); this.list.splice(index, 0, child);
} }
@ -328,7 +328,7 @@ var DisplayList = new Class({
{ {
return false; return false;
} }
else if (child.parent === this.state) else if (child.parent === this.scene)
{ {
return true; return true;
} }
@ -347,7 +347,7 @@ var DisplayList = new Class({
*/ */
bringToTop: function (child) bringToTop: function (child)
{ {
if (child.parent === this.state && this.getIndex(child) < this.list.length) if (child.parent === this.scene && this.getIndex(child) < this.list.length)
{ {
this.remove(child); this.remove(child);
this.add(child); this.add(child);
@ -365,7 +365,7 @@ var DisplayList = new Class({
*/ */
sendToBack: function (child) sendToBack: function (child)
{ {
if (child.parent === this.state && this.getIndex(child) > 0) if (child.parent === this.scene && this.getIndex(child) > 0)
{ {
this.remove(child); this.remove(child);
this.addAt(child, 0); this.addAt(child, 0);
@ -573,7 +573,7 @@ var DisplayList = new Class({
*/ */
reparent: function (newParent) reparent: function (newParent)
{ {
if (newParent !== this.state) if (newParent !== this.scene)
{ {
for (var i = 0; i < this.list.length; i++) for (var i = 0; i < this.list.length; i++)
{ {

View file

@ -20,84 +20,84 @@ var GameObjectCreator = new Class({
initialize: initialize:
function GameObjectCreator (state) function GameObjectCreator (scene)
{ {
this.state = state; this.scene = scene;
}, },
bitmapText: function (config) bitmapText: function (config)
{ {
return StaticBitmapTextCreator(this.state, config); return StaticBitmapTextCreator(this.scene, config);
}, },
dynamicBitmapText: function (config) dynamicBitmapText: function (config)
{ {
return DynamicBitmapTextCreator(this.state, config); return DynamicBitmapTextCreator(this.scene, config);
}, },
blitter: function (config) blitter: function (config)
{ {
return BlitterCreator(this.state, config); return BlitterCreator(this.scene, config);
}, },
effectLayer: function (config) effectLayer: function (config)
{ {
return EffectLayerCreator(this.state, config); return EffectLayerCreator(this.scene, config);
}, },
graphics: function (config) graphics: function (config)
{ {
return GraphicsCreator(this.state, config); return GraphicsCreator(this.scene, config);
}, },
group: function (config) group: function (config)
{ {
return GroupCreator(this.state, config); return GroupCreator(this.scene, config);
}, },
mesh: function (config) mesh: function (config)
{ {
return MeshCreator(this.state, config); return MeshCreator(this.scene, config);
}, },
image: function (config) image: function (config)
{ {
return ImageCreator(this.state, config); return ImageCreator(this.scene, config);
}, },
quad: function (config) quad: function (config)
{ {
return QuadCreator(this.state, config); return QuadCreator(this.scene, config);
}, },
renderPass: function (config) renderPass: function (config)
{ {
return RenderPassCreator(this.state, config); return RenderPassCreator(this.scene, config);
}, },
sprite: function (config) sprite: function (config)
{ {
return SpriteCreator(this.state, config); return SpriteCreator(this.scene, config);
}, },
text: function (config) text: function (config)
{ {
return TextCreator(this.state, config); return TextCreator(this.scene, config);
}, },
tilemap: function (config) tilemap: function (config)
{ {
return DynamicTilemapCreator(this.state, config); return DynamicTilemapCreator(this.scene, config);
}, },
staticTilemap: function (config) staticTilemap: function (config)
{ {
return StaticTilemapCreator(this.state, config); return StaticTilemapCreator(this.scene, config);
}, },
tileSprite: function (config) tileSprite: function (config)
{ {
return TileSpriteCreator(this.state, config); return TileSpriteCreator(this.scene, config);
} }
}); });

View file

@ -20,12 +20,12 @@ var GameObjectFactory = new Class({
initialize: initialize:
function GameObjectFactory (state) function GameObjectFactory (scene)
{ {
this.state = state; this.scene = scene;
this.displayList = state.sys.displayList; this.displayList = scene.sys.displayList;
this.updateList = state.sys.updateList; this.updateList = scene.sys.updateList;
}, },
existing: function (child) existing: function (child)
@ -45,57 +45,57 @@ var GameObjectFactory = new Class({
bitmapText: function (x, y, font, text, size, align) bitmapText: function (x, y, font, text, size, align)
{ {
return this.displayList.add(StaticBitmapTextFactory(this.state, x, y, font, text, size, align)); return this.displayList.add(StaticBitmapTextFactory(this.scene, x, y, font, text, size, align));
}, },
dynamicBitmapText: function (x, y, font, text, size, align) dynamicBitmapText: function (x, y, font, text, size, align)
{ {
return this.displayList.add(DynamicBitmapTextFactory(this.state, x, y, font, text, size, align)); return this.displayList.add(DynamicBitmapTextFactory(this.scene, x, y, font, text, size, align));
}, },
blitter: function (x, y, key, frame) blitter: function (x, y, key, frame)
{ {
return this.displayList.add(BlitterFactory(this.state, x, y, key, frame)); return this.displayList.add(BlitterFactory(this.scene, x, y, key, frame));
}, },
effectLayer: function (x, y, width, height, effectName, fragmentShader) effectLayer: function (x, y, width, height, effectName, fragmentShader)
{ {
return this.displayList.add(EffectLayerFactory(this.state, x, y, width, height, effectName, fragmentShader)); return this.displayList.add(EffectLayerFactory(this.scene, x, y, width, height, effectName, fragmentShader));
}, },
graphics: function (config) graphics: function (config)
{ {
return this.displayList.add(GraphicsFactory(this.state, config)); return this.displayList.add(GraphicsFactory(this.scene, config));
}, },
group: function (displayList, config) group: function (displayList, config)
{ {
return GroupFactory(this.state, displayList, config); return GroupFactory(this.scene, displayList, config);
}, },
image: function (x, y, key, frame) image: function (x, y, key, frame)
{ {
return this.displayList.add(ImageFactory(this.state, x, y, key, frame)); return this.displayList.add(ImageFactory(this.scene, x, y, key, frame));
}, },
mesh: function (x, y, vertices, uv, key, frame) mesh: function (x, y, vertices, uv, key, frame)
{ {
return this.displayList.add(MeshFactory(this.state, x, y, vertices, uv, key, frame)); return this.displayList.add(MeshFactory(this.scene, x, y, vertices, uv, key, frame));
}, },
quad: function (x, y, key, frame) quad: function (x, y, key, frame)
{ {
return this.displayList.add(QuadFactory(this.state, x, y, key, frame)); return this.displayList.add(QuadFactory(this.scene, x, y, key, frame));
}, },
renderPass: function (x, y, width, height, shaderName, fragmentShader) renderPass: function (x, y, width, height, shaderName, fragmentShader)
{ {
return this.displayList.add(RenderPassFactory(this.state, x, y, width, height, shaderName, fragmentShader)); return this.displayList.add(RenderPassFactory(this.scene, x, y, width, height, shaderName, fragmentShader));
}, },
sprite: function (x, y, key, frame) sprite: function (x, y, key, frame)
{ {
var sprite = SpriteFactory(this.state, x, y, key, frame); var sprite = SpriteFactory(this.scene, x, y, key, frame);
this.displayList.add(sprite); this.displayList.add(sprite);
this.updateList.add(sprite); this.updateList.add(sprite);
@ -105,22 +105,22 @@ var GameObjectFactory = new Class({
text: function (x, y, text, style) text: function (x, y, text, style)
{ {
return this.displayList.add(TextFactory(this.state, x, y, text, style)); return this.displayList.add(TextFactory(this.scene, x, y, text, style));
}, },
tilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) tilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
return this.displayList.add(DynamicTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); return this.displayList.add(DynamicTilemapFactory(this.scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
}, },
staticTilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) staticTilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
{ {
return this.displayList.add(StaticTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); return this.displayList.add(StaticTilemapFactory(this.scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
}, },
tileSprite: function (x, y, width, height, key, frame) tileSprite: function (x, y, width, height, key, frame)
{ {
return this.displayList.add(TileSpriteFactory(this.state, x, y, width, height, key, frame)); return this.displayList.add(TileSpriteFactory(this.scene, x, y, width, height, key, frame));
} }
}); });

View file

@ -5,17 +5,17 @@ var InputManager = new Class({
initialize: initialize:
function InputManager (state, game) function InputManager (scene, game)
{ {
// The State that owns this plugin // The Scene that owns this plugin
this.state = state; this.scene = scene;
this.cameras; this.cameras;
// GlobalInputManager // GlobalInputManager
this.manager = game.input; this.manager = game.input;
// Should use State event dispatcher? // Should use Scene event dispatcher?
this.events = this.manager.events; this.events = this.manager.events;
this.keyboard = this.manager.keyboard; this.keyboard = this.manager.keyboard;
@ -36,7 +36,7 @@ var InputManager = new Class({
boot: function () boot: function ()
{ {
this.cameras = this.state.sys.cameras.cameras; this.cameras = this.scene.sys.cameras.cameras;
}, },
begin: function () begin: function ()
@ -90,7 +90,7 @@ var InputManager = new Class({
return; return;
} }
// Has the pointer moved? If so we need to re-check the interactive objects per camera in this State // Has the pointer moved? If so we need to re-check the interactive objects per camera in this Scene
if (this.manager.activePointer.dirty) if (this.manager.activePointer.dirty)
{ {
this.hitTestPointer(this.manager.activePointer); this.hitTestPointer(this.manager.activePointer);

View file

@ -1,6 +1,6 @@
var BaseLoader = require('../loader/BaseLoader'); var BaseLoader = require('../loader/BaseLoader');
var Class = require('../utils/Class'); var Class = require('../utils/Class');
var CONST = require('../loader/const'); // var CONST = require('../loader/const');
var NumberArray = require('../utils/array/NumberArray'); var NumberArray = require('../utils/array/NumberArray');
var AnimationJSONFile = require('../loader/filetypes/AnimationJSONFile'); var AnimationJSONFile = require('../loader/filetypes/AnimationJSONFile');
@ -25,15 +25,15 @@ var Loader = new Class({
initialize: initialize:
function Loader (state) function Loader (scene)
{ {
BaseLoader.call(this); BaseLoader.call(this);
/** /**
* @property {Phaser.State} state - The State that owns this Factory * @property {Phaser.Scene} scene - The Scene that owns this Factory
* @protected * @protected
*/ */
this.state = state; this.scene = scene;
this._multilist = {}; this._multilist = {};
}, },
@ -248,9 +248,9 @@ var Loader = new Class({
} }
// The global Texture Manager // The global Texture Manager
var cache = this.state.sys.cache; var cache = this.scene.sys.cache;
var textures = this.state.sys.textures; var textures = this.scene.sys.textures;
var anims = this.state.sys.anims; var anims = this.scene.sys.anims;
// Process multiatlas groups first // Process multiatlas groups first

View file

@ -6,9 +6,9 @@ var PoolManager = new Class({
initialize: initialize:
function PoolManager (state) function PoolManager (scene)
{ {
this.state = state; this.scene = scene;
this._active = []; this._active = [];
this._pendingInsertion = []; this._pendingInsertion = [];
@ -102,7 +102,7 @@ var PoolManager = new Class({
this.processing = false; this.processing = false;
}, },
// State that owns this Pool is shutting down // Scene that owns this Pool is shutting down
shutdown: function () shutdown: function ()
{ {
var i; var i;
@ -132,7 +132,7 @@ var PoolManager = new Class({
{ {
this.shutdown(); this.shutdown();
this.state = undefined; this.scene = undefined;
} }
}); });

View file

@ -1,21 +1,21 @@
var Class = require('../utils/Class'); var Class = require('../utils/Class');
// A proxy class to the Global State Manager // A proxy class to the Global Scene Manager
var StateManager = new Class({ var SceneManager = new Class({
initialize: initialize:
function StateManager (state, game) function SceneManager (scene, game)
{ {
// The State that owns this plugin // The Scene that owns this plugin
this.state = state; this.scene = scene;
this.settings = state.sys.settings; this.settings = scene.sys.settings;
this.key = state.sys.settings.key; this.key = scene.sys.settings.key;
// GlobalStateManager // GlobalSceneManager
this.manager = game.state; this.manager = game.scene;
// Private // Private
this._queue = []; this._queue = [];
@ -101,7 +101,7 @@ var StateManager = new Class({
this._queue.length = 0; this._queue.length = 0;
}, },
// Shutdown this State and run the given one // Shutdown this Scene and run the given one
start: function (key, data) start: function (key, data)
{ {
if (key === undefined) { key = this.key; } if (key === undefined) { key = this.key; }
@ -111,15 +111,15 @@ var StateManager = new Class({
return this; return this;
}, },
// Add the State into the State Manager and start it if 'autoStart' is true or the State config 'active' property is set // Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set
add: function (key, stateConfig, autoStart) add: function (key, sceneConfig, autoStart)
{ {
this._queue.push({ type: 'add', key: key, data: stateConfig, autoStart: autoStart }); this._queue.push({ type: 'add', key: key, data: sceneConfig, autoStart: autoStart });
return this; return this;
}, },
// Launch the given State and run it in parallel with this one // Launch the given Scene and run it in parallel with this one
launch: function (key, data) launch: function (key, data)
{ {
if (key === undefined) { key = this.key; } if (key === undefined) { key = this.key; }
@ -129,7 +129,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Pause the State - this stops the update step from happening but it still renders // Pause the Scene - this stops the update step from happening but it still renders
pause: function (key) pause: function (key)
{ {
if (key === undefined) { key = this.key; } if (key === undefined) { key = this.key; }
@ -139,7 +139,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Resume the State - starts the update loop again // Resume the Scene - starts the update loop again
resume: function (key) resume: function (key)
{ {
if (key === undefined) { key = this.key; } if (key === undefined) { key = this.key; }
@ -149,7 +149,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Makes the State sleep (no update, no render) but doesn't shutdown // Makes the Scene sleep (no update, no render) but doesn't shutdown
sleep: function (key) sleep: function (key)
{ {
this._queue.push({ type: 'sleep', key: key }); this._queue.push({ type: 'sleep', key: key });
@ -157,7 +157,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Makes the State wake-up (starts update and render) // Makes the Scene wake-up (starts update and render)
wake: function (key) wake: function (key)
{ {
this._queue.push({ type: 'wake', key: key }); this._queue.push({ type: 'wake', key: key });
@ -165,7 +165,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Makes this State sleep then starts the State given // Makes this Scene sleep then starts the Scene given
swap: function (key) swap: function (key)
{ {
this._queue.push({ type: 'swap', key: key }); this._queue.push({ type: 'swap', key: key });
@ -173,7 +173,7 @@ var StateManager = new Class({
return this; return this;
}, },
// Shutdown the State, clearing display list, timers, etc // Shutdown the Scene, clearing display list, timers, etc
stop: function (key) stop: function (key)
{ {
if (key === undefined) { key = this.key; } if (key === undefined) { key = this.key; }
@ -217,7 +217,7 @@ var StateManager = new Class({
get: function (key) get: function (key)
{ {
return this.manager.getState(key); return this.manager.getScene(key);
}, },
transitionTo: function (key, duration) transitionTo: function (key, duration)
@ -233,4 +233,4 @@ var StateManager = new Class({
}); });
module.exports = StateManager; module.exports = SceneManager;

View file

@ -4,9 +4,9 @@ var UpdateList = new Class({
initialize: initialize:
function UpdateList (state) function UpdateList (scene)
{ {
this.state = state; this.scene = scene;
this._list = []; this._list = [];
this._pendingInsertion = []; this._pendingInsertion = [];
@ -69,7 +69,7 @@ var UpdateList = new Class({
} }
}, },
// State that owns this Clock is shutting down // Scene that owns this Clock is shutting down
shutdown: function () shutdown: function ()
{ {
var i; var i;
@ -99,7 +99,7 @@ var UpdateList = new Class({
{ {
this.shutdown(); this.shutdown();
this.state = undefined; this.scene = undefined;
} }
}); });

View file

@ -24,7 +24,7 @@ var CanvasRenderer = new Class({
this.drawCount = 0; this.drawCount = 0;
// Read all the following from game config (or State config?) // Read all the following from game config (or Scene config?)
// this.clearBeforeRender = true; // this.clearBeforeRender = true;
// this.transparent = false; // this.transparent = false;
// this.autoResize = false; // this.autoResize = false;
@ -148,20 +148,20 @@ var CanvasRenderer = new Class({
}, },
/** /**
* Renders the State. * Renders the Scene.
* *
* @method render * @method render
* @param {Phaser.State} state - The State to be rendered. * @param {Phaser.Scene} scene - The Scene to be rendered.
* @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided * @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided
* by the amount of time that will be simulated the next time update() * by the amount of time that will be simulated the next time update()
* runs. Useful for interpolating frames. * runs. Useful for interpolating frames.
*/ */
render: function (state, children, interpolationPercentage, camera) render: function (scene, children, interpolationPercentage, camera)
{ {
var w = state.sys.width; // var w = scene.sys.width;
var h = state.sys.height; // var h = scene.sys.height;
var ctx = state.sys.context; var ctx = scene.sys.context;
var settings = state.sys.settings; var settings = scene.sys.settings;
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height); var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
var list = children.list; var list = children.list;
@ -211,8 +211,8 @@ var CanvasRenderer = new Class({
child.renderCanvas(this, child, interpolationPercentage, camera); child.renderCanvas(this, child, interpolationPercentage, camera);
} }
// Call the State.render function // Call the Scene.render function
state.render.call(state, ctx, interpolationPercentage); scene.render.call(scene, ctx, interpolationPercentage);
ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.setTransform(1, 0, 0, 1, 0, 0);
@ -238,10 +238,10 @@ var CanvasRenderer = new Class({
} }
// Blast it to the Game Canvas (if needed) // Blast it to the Game Canvas (if needed)
if (settings.renderToTexture) // if (settings.renderToTexture)
{ // {
this.gameContext.drawImage(state.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h); // this.gameContext.drawImage(scene.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h);
} // }
}, },
postRender: function () postRender: function ()

View file

@ -295,15 +295,15 @@ var WebGLRenderer = new Class({
}, },
/** /**
* Renders a single State. * Renders a single Scene.
* *
* @method render * @method render
* @param {Phaser.State} state - The State to be rendered. * @param {Phaser.Scene} scene - The Scene to be rendered.
* @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided * @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided
* by the amount of time that will be simulated the next time update() * by the amount of time that will be simulated the next time update()
* runs. Useful for interpolating frames. * runs. Useful for interpolating frames.
*/ */
render: function (state, children, interpolationPercentage, camera) render: function (scene, children, interpolationPercentage, camera)
{ {
var gl = this.gl; var gl = this.gl;
var quadBatch = this.quadBatch; var quadBatch = this.quadBatch;

View file

@ -1,4 +1,4 @@
// These properties get injected into the State Factory Plugin // These properties get injected into the Scene Factory Plugin
// The key is the factory reference, the value is the Game Object that is created // The key is the factory reference, the value is the Game Object that is created
// These can be modified via the config object // These can be modified via the config object

View file

@ -1,39 +1,39 @@
var Components = require('./components/'); var Components = require('./components/');
var Class = require('../utils/Class'); var Class = require('../utils/Class');
var GlobalStateManager = new Class({ var GlobalSceneManager = new Class({
initialize: initialize:
function GlobalStateManager (game, stateConfig) function GlobalSceneManager (game, sceneConfig)
{ {
this.game = game; this.game = game;
// Everything kept in here // Everything kept in here
this.keys = {}; this.keys = {};
this.states = []; this.scenes = [];
// Only active states are kept in here. They are moved here when started, and moved out when not. // Only active scenes are kept in here. They are moved here when started, and moved out when not.
// All states are stored in the states array, regardless of being active or not. // All scenes are stored in the scenes array, regardless of being active or not.
this.active = []; this.active = [];
// A state pending to be added to the State Manager is stored in here until the manager has time to add it. // A scene pending to be added to the Scene Manager is stored in here until the manager has time to add it.
this._pending = []; this._pending = [];
// An array of states waiting to be started once the game has booted // An array of scenes waiting to be started once the game has booted
this._start = []; this._start = [];
if (stateConfig) if (sceneConfig)
{ {
if (Array.isArray(stateConfig)) if (Array.isArray(sceneConfig))
{ {
for (var i = 0; i < stateConfig.length; i++) for (var i = 0; i < sceneConfig.length; i++)
{ {
// The i === 0 part just starts the first State given // The i === 0 part just starts the first Scene given
this._pending.push({ this._pending.push({
index: i, index: i,
key: 'default', key: 'default',
state: stateConfig[i], scene: sceneConfig[i],
autoStart: (i === 0), autoStart: (i === 0),
data: {} data: {}
}); });
@ -44,7 +44,7 @@ var GlobalStateManager = new Class({
this._pending.push({ this._pending.push({
index: 0, index: 0,
key: 'default', key: 'default',
state: stateConfig, scene: sceneConfig,
autoStart: true, autoStart: true,
data: {} data: {}
}); });
@ -54,21 +54,21 @@ var GlobalStateManager = new Class({
add: Components.Add, add: Components.Add,
boot: Components.Boot, boot: Components.Boot,
bootState: Components.BootState, bootScene: Components.BootScene,
bringToTop: Components.BringToTop, bringToTop: Components.BringToTop,
create: Components.Create, create: Components.Create,
createStateDisplay: Components.CreateStateDisplay, createSceneDisplay: Components.CreateSceneDisplay,
createStateFromFunction: Components.CreateStateFromFunction, createSceneFromFunction: Components.CreateSceneFromFunction,
createStateFromInstance: Components.CreateStateFromInstance, createSceneFromInstance: Components.CreateSceneFromInstance,
createStateFromObject: Components.CreateStateFromObject, createSceneFromObject: Components.CreateSceneFromObject,
getActiveState: Components.GetActiveState, getActiveScene: Components.GetActiveScene,
getActiveStateIndex: Components.GetActiveStateIndex, getActiveSceneIndex: Components.GetActiveSceneIndex,
getActiveStateIndexByKey: Components.GetActiveStateIndexByKey, getActiveSceneIndexByKey: Components.GetActiveSceneIndexByKey,
getKey: Components.GetKey, getKey: Components.GetKey,
getState: Components.GetState, getScene: Components.GetScene,
getStateAt: Components.GetStateAt, getSceneAt: Components.GetSceneAt,
getStateIndex: Components.GetStateIndex, getSceneIndex: Components.GetSceneIndex,
getStateIndexByKey: Components.GetStateIndexByKey, getSceneIndexByKey: Components.GetSceneIndexByKey,
isActive: Components.IsActive, isActive: Components.IsActive,
isSleeping: Components.IsSleeping, isSleeping: Components.IsSleeping,
loadComplete: Components.LoadComplete, loadComplete: Components.LoadComplete,
@ -88,4 +88,4 @@ var GlobalStateManager = new Class({
}); });
module.exports = GlobalStateManager; module.exports = GlobalSceneManager;

View file

@ -1,5 +1,5 @@
// These properties get injected into the State and map to local systems // These properties get injected into the Scene and map to local systems
// The key is the local system reference, the value is the property that is added to the State // The key is the local system reference, the value is the property that is added to the Scene
// These can be modified via the config object // These can be modified via the config object
var InjectionMap = { var InjectionMap = {
@ -20,7 +20,7 @@ var InjectionMap = {
load: 'load', load: 'load',
make: 'make', make: 'make',
pool: 'pool', pool: 'pool',
stateManager: 'state', sceneManager: 'scene',
time: 'time', time: 'time',
tweens: 'tweens' tweens: 'tweens'

View file

@ -2,26 +2,26 @@
var Class = require('../utils/Class'); var Class = require('../utils/Class');
var Systems = require('./Systems'); var Systems = require('./Systems');
var State = new Class({ var Scene = new Class({
initialize: initialize:
function State (config) function Scene (config)
{ {
// The State Systems. You must never overwrite this property, or all hell will break lose. // The Scene Systems. You must never overwrite this property, or all hell will break lose.
this.sys = new Systems(this, config); this.sys = new Systems(this, config);
}, },
// Should be overridden by your own States // Should be overridden by your own Scenes
update: function () update: function ()
{ {
}, },
// Should be overridden by your own States // Should be overridden by your own Scenes
render: function () render: function ()
{ {
} }
}); });
module.exports = State; module.exports = Scene;

View file

@ -37,11 +37,11 @@ var Settings = {
cameras: GetValue(config, 'cameras', null), cameras: GetValue(config, 'cameras', null),
// State Property Injection Map // Scene Property Injection Map
map: GetValue(config, 'map', InjectionMap), map: GetValue(config, 'map', InjectionMap),
// State Render Settings (applies only to this State) // Scene Render Settings (applies only to this Scene)
scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT), scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT),
roundPixels: GetValue(config, 'roundPixels', false), roundPixels: GetValue(config, 'roundPixels', false),

View file

@ -12,7 +12,7 @@ var Loader = require('../plugins/Loader');
var PoolManager = require('../plugins/PoolManager'); var PoolManager = require('../plugins/PoolManager');
var Settings = require('./Settings'); var Settings = require('./Settings');
var StableSort = require('../utils/array/StableSort'); var StableSort = require('../utils/array/StableSort');
var StateManager = require('../plugins/StateManager'); var SceneManager = require('../plugins/SceneManager');
var TweenManager = require('../tween/TweenManager'); var TweenManager = require('../tween/TweenManager');
var UpdateList = require('../plugins/UpdateList'); var UpdateList = require('../plugins/UpdateList');
@ -20,16 +20,16 @@ var Systems = new Class({
initialize: initialize:
function Systems (state, config) function Systems (scene, config)
{ {
this.state = state; this.scene = scene;
this.config = config; this.config = config;
this.settings = Settings.create(config); this.settings = Settings.create(config);
this.sortChildrenFlag = false; this.sortChildrenFlag = false;
// Set by the GlobalStateManager // Set by the GlobalSceneManager
this.mask = null; this.mask = null;
this.canvas; this.canvas;
this.context; this.context;
@ -43,7 +43,7 @@ var Systems = new Class({
this.registry; this.registry;
this.textures; this.textures;
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc) // Reference to Scene specific managers (Factory, Tweens, Loader, Physics, etc)
this.add; this.add;
this.cameras; this.cameras;
this.events; this.events;
@ -51,11 +51,11 @@ var Systems = new Class({
this.load; this.load;
this.make; this.make;
this.pool; this.pool;
this.stateManager; this.sceneManager;
this.time; this.time;
this.tweens; this.tweens;
// State properties // Scene properties
this.updateList; this.updateList;
this.displayList; this.displayList;
this.data; this.data;
@ -63,7 +63,7 @@ var Systems = new Class({
init: function (game) init: function (game)
{ {
var state = this.state; var scene = this.scene;
this.game = game; this.game = game;
@ -74,24 +74,24 @@ var Systems = new Class({
this.registry = game.registry; this.registry = game.registry;
this.textures = game.textures; this.textures = game.textures;
// State specific properties (transform, data, children, etc) // Scene specific properties (transform, data, children, etc)
this.inputManager = new InputManager(state, game); this.inputManager = new InputManager(scene, game);
this.updateList = new UpdateList(state); this.updateList = new UpdateList(scene);
this.displayList = new DisplayList(state); this.displayList = new DisplayList(scene);
this.data = new Data(state); this.data = new Data(scene);
// State specific managers (Factory, Tweens, Loader, Physics, etc) // Scene specific managers (Factory, Tweens, Loader, Physics, etc)
this.add = new GameObjectFactory(state); this.add = new GameObjectFactory(scene);
this.cameras = new CameraManager(state); this.cameras = new CameraManager(scene);
this.events = new EventDispatcher(); this.events = new EventDispatcher();
this.load = new Loader(state); this.load = new Loader(scene);
this.make = new GameObjectCreator(state); this.make = new GameObjectCreator(scene);
this.pool = new PoolManager(state); this.pool = new PoolManager(scene);
this.stateManager = new StateManager(state, game); this.sceneManager = new SceneManager(scene, game);
this.time = new Clock(state); this.time = new Clock(scene);
this.tweens = new TweenManager(state); this.tweens = new TweenManager(scene);
// Sometimes the managers need access to a system created after them // Sometimes the managers need access to a system created after them
this.inputManager.boot(); this.inputManager.boot();
@ -110,14 +110,14 @@ var Systems = new Class({
continue; continue;
} }
this.state[map[key]] = this[key]; this.scene[map[key]] = this[key];
} }
}, },
step: function (time, delta) step: function (time, delta)
{ {
// Are there any pending StateManager actions? // Are there any pending SceneManager actions?
this.stateManager.update(); this.sceneManager.update();
if (!this.settings.active) if (!this.settings.active)
{ {
@ -137,7 +137,7 @@ var Systems = new Class({
this.cameras.update(time, delta); this.cameras.update(time, delta);
this.inputManager.update(time, delta); this.inputManager.update(time, delta);
this.state.update.call(this.state, time, delta); this.scene.update.call(this.scene, time, delta);
}, },
render: function (interpolation, renderer) render: function (interpolation, renderer)
@ -168,60 +168,60 @@ var Systems = new Class({
return childA._z - childB._z; return childA._z - childB._z;
}, },
// A paused State still renders, it just doesn't run ANY of its update handlers or systems // A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
pause: function () pause: function ()
{ {
// Was paused by the GlobalStateManager // Was paused by the GlobalSceneManager
this.settings.active = false; this.settings.active = false;
if (this.state.pause) if (this.scene.pause)
{ {
this.state.pause.call(this.state); this.scene.pause.call(this.scene);
} }
}, },
resume: function () resume: function ()
{ {
// Was resumed by the GlobalStateManager // Was resumed by the GlobalSceneManager
this.settings.active = true; this.settings.active = true;
if (this.state.resume) if (this.scene.resume)
{ {
this.state.resume.call(this.state); this.scene.resume.call(this.scene);
} }
}, },
sleep: function () sleep: function ()
{ {
// Was sent to sleep by the GlobalStateManager // Was sent to sleep by the GlobalSceneManager
this.settings.active = false; this.settings.active = false;
this.settings.visible = false; this.settings.visible = false;
if (this.state.sleep) if (this.scene.sleep)
{ {
this.state.sleep.call(this.state); this.scene.sleep.call(this.scene);
} }
}, },
wake: function () wake: function ()
{ {
// Was woken up by the GlobalStateManager // Was woken up by the GlobalSceneManager
this.settings.active = true; this.settings.active = true;
this.settings.visible = true; this.settings.visible = true;
if (this.state.wake) if (this.scene.wake)
{ {
this.state.wake.call(this.state); this.scene.wake.call(this.scene);
} }
}, },
start: function (data) start: function (data)
{ {
// Was started by the GlobalStateManager // Was started by the GlobalSceneManager
this.settings.data = data; this.settings.data = data;
@ -231,7 +231,7 @@ var Systems = new Class({
shutdown: function () shutdown: function ()
{ {
// Was stopped by the GlobalStateManager // Was stopped by the GlobalSceneManager
this.settings.active = false; this.settings.active = false;
this.settings.visible = false; this.settings.visible = false;
@ -242,9 +242,9 @@ var Systems = new Class({
this.time.shutdown(); this.time.shutdown();
this.tweens.shutdown(); this.tweens.shutdown();
if (this.state.shutdown) if (this.scene.shutdown)
{ {
this.state.shutdown.call(this.state); this.scene.shutdown.call(this.scene);
} }
}, },
@ -258,9 +258,9 @@ var Systems = new Class({
this.tweens.destroy(); this.tweens.destroy();
// etc // etc
if (this.state.destroy) if (this.scene.destroy)
{ {
this.state.destroy.call(this.state); this.scene.destroy.call(this.scene);
} }
} }

View file

@ -0,0 +1,89 @@
var Scene = require('../Scene');
/**
* Adds a new Scene into the GlobalSceneManager. You must give each Scene a unique key by which you'll identify it.
* The Scene can be either a Phaser.Scene object (or an object that extends it), a plain JavaScript object or a function.
* If a function is given a new scene object will be created by calling it.
*
* @method Phaser.GlobalSceneManager#add
* @param {string} key - A unique key you use to reference this scene, i.e. "MainMenu", "Level1".
* @param {Phaser.Scene|object|function} scene - The scene you want to switch to.
* @param {boolean} [autoStart=false] - If true the Scene will be started immediately after adding it.
*/
var Add = function (key, sceneConfig, autoStart)
{
if (autoStart === undefined) { autoStart = false; }
// if not booted, then put scene into a holding pattern
if (!this.game.isBooted)
{
this._pending.push({
index: this._pending.length,
key: key,
scene: sceneConfig,
autoStart: autoStart
});
// console.log('GlobalSceneManager not yet booted, adding to list', this._pending.length);
return;
}
// var ok = key;
key = this.getKey(key, sceneConfig);
// console.group('GlobalSceneManager.add');
// console.log('add key:', ok);
// console.log('config key:', key);
// console.log('config:', sceneConfig);
// console.log('autoStart:', autoStart);
// console.groupEnd();
var newScene;
if (sceneConfig instanceof Scene)
{
// console.log('GlobalSceneManager.add from instance:', key);
newScene = this.createSceneFromInstance(key, sceneConfig);
}
else if (typeof sceneConfig === 'object')
{
// console.log('GlobalSceneManager.add from object:', key);
sceneConfig.key = key;
newScene = this.createSceneFromObject(key, sceneConfig);
}
else if (typeof sceneConfig === 'function')
{
// console.log('GlobalSceneManager.add from function:', key);
newScene = this.createSceneFromFunction(key, sceneConfig);
}
// Replace key in case the scene changed it
key = newScene.sys.settings.key;
// console.log('replaced key', key);
this.keys[key] = newScene;
this.scenes.push(newScene);
if (autoStart || newScene.sys.settings.active)
{
if (this.game.isBooted)
{
this.start(key);
}
else
{
this._start.push(key);
}
}
return newScene;
};
module.exports = Add;

View file

@ -2,7 +2,7 @@
* The Boot handler is called by Phaser.Game when it first starts up. * The Boot handler is called by Phaser.Game when it first starts up.
* The renderer is available by now. * The renderer is available by now.
* *
* @method Phaser.GlobalStateManager#boot * @method Phaser.GlobalSceneManager#boot
* @private * @private
*/ */
var Boot = function () var Boot = function ()
@ -14,7 +14,7 @@ var Boot = function ()
{ {
entry = this._pending[i]; entry = this._pending[i];
this.add(entry.key, entry.state, entry.autoStart); this.add(entry.key, entry.scene, entry.autoStart);
} }
for (i = 0; i < this._start.length; i++) for (i = 0; i < this._start.length; i++)

View file

@ -1,24 +1,24 @@
var BootState = function (state) var BootScene = function (scene)
{ {
// console.log('bootState', state.sys.settings.key); // console.log('bootScene', scene.sys.settings.key);
if (state.init) if (scene.init)
{ {
state.init.call(state, state.sys.settings.data); scene.init.call(scene, scene.sys.settings.data);
} }
var loader = state.sys.load; var loader = scene.sys.load;
loader.reset(); loader.reset();
if (state.preload) if (scene.preload)
{ {
state.preload(this.game); scene.preload(this.game);
// Is the loader empty? // Is the loader empty?
if (loader.list.size === 0) if (loader.list.size === 0)
{ {
this.create(state); this.create(scene);
} }
else else
{ {
@ -32,8 +32,8 @@ var BootState = function (state)
else else
{ {
// No preload? Then there was nothing to load either // No preload? Then there was nothing to load either
this.create(state); this.create(scene);
} }
}; };
module.exports = BootState; module.exports = BootScene;

View file

@ -1,9 +1,9 @@
// If the arguments are strings they are assumed to be keys, otherwise they are State objects // If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. // You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
var BringToTop = function (state) var BringToTop = function (scene)
{ {
var index = (typeof state === 'string') ? this.getActiveStateIndexByKey(state) : this.getActiveStateIndex(state); var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene);
if (index < this.active.length) if (index < this.active.length)
{ {
@ -15,7 +15,7 @@ var BringToTop = function (state)
this.active[i].index = i; this.active[i].index = i;
} }
this.active.push({ index: i, state: entry[0].state }); this.active.push({ index: i, scene: entry[0].scene });
} }
}; };

View file

@ -0,0 +1,25 @@
var SortScenes = require('./SortScenes');
var Create = function (scene)
{
// console.log('create', scene.sys.settings.key);
// console.log(scene);
// Insert at the correct index, or it just all goes wrong :)
var i = this.getSceneIndex(scene);
// console.log('create.index', scene.sys.settings.key, i);
this.active.push({ index: i, scene: scene });
// Sort the 'active' array based on the index property
this.active.sort(SortScenes);
if (scene.create)
{
scene.create.call(scene, scene.sys.settings.data);
}
};
module.exports = Create;

View file

@ -3,11 +3,11 @@ var CONST = require('../../const');
var GetContext = require('../../canvas/GetContext'); var GetContext = require('../../canvas/GetContext');
var CanvasInterpolation = require('../../dom/CanvasInterpolation'); var CanvasInterpolation = require('../../dom/CanvasInterpolation');
var CreateStateDisplay = function (state) var CreateSceneDisplay = function (scene)
{ {
// console.log('createStateDisplay', state.sys.settings.key); // console.log('createSceneDisplay', scene.sys.settings.key);
var settings = state.sys.settings; var settings = scene.sys.settings;
var width = settings.width; var width = settings.width;
var height = settings.height; var height = settings.height;
@ -19,23 +19,23 @@ var CreateStateDisplay = function (state)
if (settings.renderToTexture) if (settings.renderToTexture)
{ {
// console.log('renderToTexture', width, height); // console.log('renderToTexture', width, height);
state.sys.canvas = CanvasPool.create(state, width, height); scene.sys.canvas = CanvasPool.create(scene, width, height);
state.sys.context = GetContext(state.sys.canvas); scene.sys.context = GetContext(scene.sys.canvas);
} }
else else
{ {
// console.log('using game canvas'); // console.log('using game canvas');
// state.sys.mask = new Rectangle(0, 0, width, height); // scene.sys.mask = new Rectangle(0, 0, width, height);
state.sys.canvas = this.game.canvas; scene.sys.canvas = this.game.canvas;
state.sys.context = this.game.context; scene.sys.context = this.game.context;
} }
// Pixel Art mode? // Pixel Art mode?
if (config.pixelArt) if (config.pixelArt)
{ {
CanvasInterpolation.setCrisp(state.sys.canvas); CanvasInterpolation.setCrisp(scene.sys.canvas);
} }
} }
}; };
module.exports = CreateStateDisplay; module.exports = CreateSceneDisplay;

View file

@ -0,0 +1,75 @@
var Scene = require('../Scene');
var Systems = require('../Systems');
var NOOP = require('../../utils/NOOP');
var CreateSceneFromFunction = function (key, scene)
{
// console.log('createSceneFromFunction', key);
var newScene = new scene();
if (newScene instanceof Scene)
{
// console.log('instanceof Scene');
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
return this.createSceneFromInstance(key, newScene);
}
else
{
newScene.sys = new Systems(newScene);
newScene.sys.settings.key = key;
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
// Default required functions
if (!newScene.init)
{
newScene.init = NOOP;
}
if (!newScene.preload)
{
newScene.preload = NOOP;
}
if (!newScene.create)
{
newScene.create = NOOP;
}
if (!newScene.shutdown)
{
newScene.shutdown = NOOP;
}
if (!newScene.update)
{
newScene.update = NOOP;
}
if (!newScene.render)
{
newScene.render = NOOP;
}
return newScene;
}
};
module.exports = CreateSceneFromFunction;

View file

@ -0,0 +1,21 @@
var CreateSceneFromInstance = function (key, newScene)
{
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
else
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
return newScene;
};
module.exports = CreateSceneFromInstance;

View file

@ -0,0 +1,25 @@
var Scene = require('../Scene');
var CreateSceneFromObject = function (key, sceneConfig)
{
var newScene = new Scene(sceneConfig);
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
else
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
return this.setupCallbacks(newScene, sceneConfig);
};
module.exports = CreateSceneFromObject;

View file

@ -0,0 +1,14 @@
var GetActiveScene = function (key)
{
var scene = this.getScene(key);
for (var i = 0; i < this.active.length; i++)
{
if (this.active[i].scene === scene)
{
return this.active[i];
}
}
};
module.exports = GetActiveScene;

View file

@ -1,8 +1,8 @@
var GetActiveStateIndex = function (state) var GetActiveSceneIndex = function (scene)
{ {
for (var i = 0; i < this.active.length; i++) for (var i = 0; i < this.active.length; i++)
{ {
if (this.active[i].state === state) if (this.active[i].scene === scene)
{ {
return this.active[i].index; return this.active[i].index;
} }
@ -11,4 +11,4 @@ var GetActiveStateIndex = function (state)
return -1; return -1;
}; };
module.exports = GetActiveStateIndex; module.exports = GetActiveSceneIndex;

View file

@ -0,0 +1,16 @@
var GetActiveSceneIndexByKey = function (key)
{
var scene = this.keys[key];
for (var i = 0; i < this.active.length; i++)
{
if (this.active[i].scene === scene)
{
return this.active[i].index;
}
}
return -1;
};
module.exports = GetActiveSceneIndexByKey;

View file

@ -0,0 +1,33 @@
var Scene = require('../Scene');
// private
var GetKey = function (key, sceneConfig)
{
if (!key) { key = 'default'; }
if (typeof sceneConfig === 'function')
{
return key;
}
else if (sceneConfig instanceof Scene)
{
key = sceneConfig.sys.settings.key;
}
else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key'))
{
key = sceneConfig.key;
}
// By this point it's either 'default' or extracted from the Scene
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
else
{
return key;
}
};
module.exports = GetKey;

View file

@ -0,0 +1,6 @@
var GetScene = function (key)
{
return this.keys[key];
};
module.exports = GetScene;

View file

@ -0,0 +1,11 @@
// Get's the Active scene at the given position
var GetSceneAt = function (index)
{
if (this.active[index])
{
return this.active[index].scene;
}
};
module.exports = GetSceneAt;

View file

@ -0,0 +1,6 @@
var GetSceneIndex = function (scene)
{
return this.scenes.indexOf(scene);
};
module.exports = GetSceneIndex;

View file

@ -0,0 +1,8 @@
var GetSceneIndexByKey = function (key)
{
var scene = this.keys[key];
return this.scenes.indexOf(scene);
};
module.exports = GetSceneIndexByKey;

View file

@ -0,0 +1,8 @@
var IsActive = function (key)
{
var scene = this.getScene(key);
return (scene && scene.sys.settings.active && this.active.indexOf(scene) !== -1);
};
module.exports = IsActive;

View file

@ -1,10 +1,10 @@
var IsSleeping = function (key) var IsSleeping = function (key)
{ {
var entry = this.getActiveState(key); var entry = this.getActiveScene(key);
if (entry) if (entry)
{ {
return (!entry.state.sys.settings.active && !entry.state.sys.settings.visible); return (!entry.scene.sys.settings.active && !entry.scene.sys.settings.visible);
} }
return false; return false;

View file

@ -0,0 +1,10 @@
var LoadComplete = function (event)
{
var scene = event.loader.scene;
// console.log('loadComplete', scene.sys.settings.key);
this.create(scene);
};
module.exports = LoadComplete;

Some files were not shown because too many files have changed in this diff Show more