Merge branch 'master' into rendering-cleanup

# Conflicts:
#	src/gameobjects/blitter/BlitterWebGLRenderer.js
This commit is contained in:
Felipe Alfonso 2018-01-21 11:14:27 -03:00
commit a4e79875d4
26 changed files with 1207 additions and 747 deletions

View file

@ -1,6 +1,2 @@
**/.*
dist/
docs/
merge/
examples/
v3/
wip/

View file

@ -11,8 +11,8 @@ var CoreScenePlugins = [
'GameObjectCreator',
'GameObjectFactory',
'ScenePlugin',
'DisplayList',
'UpdateList'
'DisplayListPlugin',
'UpdateListPlugin'
];

View file

@ -15,16 +15,52 @@ var Animation = new Class({
initialize:
/**
* [description]
*
* @class Animation
* @memberOf Phaser.Animations
* @constructor
* @since 3.0.0
*
* @param {undefined} manager - [description]
* @param {undefined} key - [description]
* @param {undefined} config - [description]
*/
function Animation (manager, key, config)
{
/**
* [description]
*
* @property {Phaser.Animations.AnimationManager} manager
* @since 3.0.0
*/
this.manager = manager;
/**
* [description]
*
* @property {string} key
*/
this.key = key;
// A frame based animation (as opposed to a bone based animation)
/**
* [description]
*
* @property {string} type
* @default frame
*/
this.type = 'frame';
// Extract all the frame data into the frames array
/**
* [description]
*
* @property {array} frames
*/
this.frames = this.getFrames(
manager.textureManager,
GetValue(config, 'frames', []),
@ -32,10 +68,25 @@ var Animation = new Class({
);
// The frame rate of playback in frames per second (default 24 if duration is null)
/**
* [description]
*
* @property {integer} frameRate
* @default 24
* @since 3.0.0
*/
this.frameRate = GetValue(config, 'frameRate', null);
// How long the animation should play for. If frameRate is set it overrides this value
// otherwise frameRate is derived from duration
/**
* [description]
*
* @property {integer} duration
* @since 3.0.0
*/
this.duration = GetValue(config, 'duration', null);
if (this.duration === null && this.frameRate === null)
@ -60,49 +111,171 @@ var Animation = new Class({
}
// ms per frame (without including frame specific modifiers)
/**
* [description]
*
* @property {integer} msPerFrame
*/
this.msPerFrame = 1000 / this.frameRate;
// Skip frames if the time lags, or always advanced anyway?
/**
* [description]
*
* @property {boolean} skipMissedFrames
* @default false
*/
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
// Delay before starting playback (in seconds)
/**
* [description]
*
* @property {integer} delay
* @default 0
*/
this.delay = GetValue(config, 'delay', 0);
// Number of times to repeat the animation (-1 for infinity)
/**
* [description]
*
* @property {integer} repeat
* @default 0
*/
this.repeat = GetValue(config, 'repeat', 0);
// Delay before the repeat starts (in seconds)
/**
* [description]
*
* @property {integer} repeatDelay
* @default 0
*/
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
// Should the animation yoyo? (reverse back down to the start) before repeating?
/**
* [description]
*
* @property {boolean} yoyo
* @default false
*/
this.yoyo = GetValue(config, 'yoyo', false);
// Should sprite.visible = true when the animation starts to play?
/**
* [description]
*
* @property {boolean} showOnStart
* @default false
*/
this.showOnStart = GetValue(config, 'showOnStart', false);
// Should sprite.visible = false when the animation finishes?
/**
* [description]
*
* @property {boolean} hideOnComplete
* @default false
*/
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
// Callbacks
/**
* [description]
*
* @property {object} callbackScope
*/
this.callbackScope = GetValue(config, 'callbackScope', this);
/**
* [description]
*
* @property {function} onStart
*/
this.onStart = GetValue(config, 'onStart', false);
/**
* [description]
*
* @property {array} onStartParams
*/
this.onStartParams = GetValue(config, 'onStartParams', []);
/**
* [description]
*
* @property {function} onRepeat
*/
this.onRepeat = GetValue(config, 'onRepeat', false);
/**
* [description]
*
* @property {array} onRepeatParams
*/
this.onRepeatParams = GetValue(config, 'onRepeatParams', []);
// Called for EVERY frame of the animation.
// See AnimationFrame.onUpdate for a frame specific callback.
/**
* [description]
*
* @property {function} onUpdate
*/
this.onUpdate = GetValue(config, 'onUpdate', false);
/**
* [description]
*
* @property {array} onUpdateParams
*/
this.onUpdateParams = GetValue(config, 'onUpdateParams', []);
/**
* [description]
*
* @property {function} onComplete
*/
this.onComplete = GetValue(config, 'onComplete', false);
/**
* [description]
*
* @property {array} onCompleteParams
*/
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
// Global pause, effects all Game Objects using this Animation instance
/**
* [description]
*
* @property {boolean} paused
* @default false
*/
this.paused = false;
/**
* [description]
*
* @property {null} manager.on('pauseall', this.pause.bind(this))
*/
this.manager.on('pauseall', this.pause.bind(this));
this.manager.on('resumeall', this.resume.bind(this));
},

View file

@ -6,43 +6,136 @@ var AnimationFrame = new Class({
initialize:
/**
* [description]
*
* @class AnimationFrame
* @memberOf Phaser.Animations.AnimationFrame
* @constructor
* @since 3.0.0
*
* @param {undefined} textureKey - [description]
* @param {undefined} textureFrame - [description]
* @param {undefined} index - [description]
* @param {undefined} frame - [description]
*/
function AnimationFrame (textureKey, textureFrame, index, frame)
{
// The keys into the Texture Manager of the texture + frame this uses
/**
* [description]
*
* @property {string} textureKey
*/
this.textureKey = textureKey;
/**
* [description]
*
* @property {Phaser.Textures.Frame} textureFrame
*/
this.textureFrame = textureFrame;
// The index of this frame within the Animation.frames array
/**
* [description]
*
* @property {integer} index
*/
this.index = index;
// Texture Frame
/**
* [description]
*
* @property {Phaser.Textures.Frame} frame
*/
this.frame = frame;
// Read-only
/**
* [description]
*
* @property {boolean} isFirst
* @default false
*/
this.isFirst = false;
// Read-only
/**
* [description]
*
* @property {boolean} isLast
* @default false
*/
this.isLast = false;
// The frame that comes before this one in the animation (if any)
// Read-only
/**
* [description]
*
* @property {?[type]} prevFrame
* @default null
*/
this.prevFrame = null;
// The frame that comes after this one in the animation (if any)
// Read-only
/**
* [description]
*
* @property {?[type]} nextFrame
* @default null
*/
this.nextFrame = null;
// Additional time (in ms) this frame should appear for - added onto the msPerFrame
/**
* [description]
*
* @property {number} duration
* @default 0
*/
this.duration = 0;
// What % through the animation progress is this frame?
// Read-only
/**
* [description]
*
* @property {number} progress
* @default 0
*/
this.progress = 0;
// Callback if this frame gets displayed
/**
* [description]
*
* @property {?[type]} onUpdate
* @default null
*/
this.onUpdate = null;
// When this frame hits, set sprite.visible to this
/**
* [description]
*
* @property {boolean} setVisible
* @default false
*/
this.setVisible = false;
this.visible = false;

View file

@ -226,9 +226,6 @@ var Game = new Class({
*/
step: function (time, delta)
{
var active = this.scene.active;
var renderer = this.renderer;
// Global Managers
this.input.update(time, delta);
@ -239,28 +236,21 @@ var Game = new Class({
this.onStepCallback();
for (var i = 0; i < active.length; i++)
{
active[i].scene.sys.step(time, delta);
}
this.scene.update(time, delta);
// Render
// var interpolation = this.frameDelta / this.timestep;
var renderer = this.renderer;
renderer.preRender();
this.events.emit('prerender');
this.events.emit('prerender', renderer);
// This uses active.length, in case scene.update removed the scene from the active list
for (i = 0; i < active.length; i++)
{
active[i].scene.sys.render(0, renderer);
}
this.scene.render(renderer);
renderer.postRender();
this.events.emit('postrender');
this.events.emit('postrender', renderer);
},
/**

View file

@ -1,23 +1,12 @@
var Class = require('../utils/Class');
var StableSort = require('../utils/array/StableSort');
var PluginManager = require('../plugins/PluginManager');
var DisplayList = new Class({
initialize:
function DisplayList (scene)
function DisplayList ()
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
// The objects that belong to this collection.
// The equivalent of the old `Sprite.children` array.
this.list = [];
@ -27,14 +16,6 @@ var DisplayList = new Class({
this.position = 0;
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
process: function ()
{
if (this.sortChildrenFlag)
@ -725,6 +706,4 @@ var DisplayList = new Class({
});
PluginManager.register('DisplayList', DisplayList, 'displayList');
module.exports = DisplayList;

View file

@ -0,0 +1,48 @@
var Class = require('../utils/Class');
var DisplayList = require('./DisplayList');
var PluginManager = require('../plugins/PluginManager');
var DisplayListPlugin = new Class({
Extends: DisplayList,
initialize:
function DisplayListPlugin (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
DisplayList.call(this);
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
shutdown: function ()
{
this.removeAll();
},
destroy: function ()
{
this.shutdown();
}
});
PluginManager.register('DisplayListPlugin', DisplayListPlugin, 'displayList');
module.exports = DisplayListPlugin;

View file

@ -1,36 +1,16 @@
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var UpdateList = new Class({
initialize:
function UpdateList (scene)
function UpdateList ()
{
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
this._list = [];
this._pendingInsertion = [];
this._pendingRemoval = [];
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
add: function (child)
{
// Is child already in this list?
@ -130,12 +110,8 @@ var UpdateList = new Class({
destroy: function ()
{
this.shutdown();
this.scene = undefined;
}
});
PluginManager.register('UpdateList', UpdateList, 'updateList');
module.exports = UpdateList;

View file

@ -0,0 +1,46 @@
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var UpdateList = require('./UpdateList');
var UpdateListPlugin = new Class({
Extends: UpdateList,
initialize:
function UpdateListPlugin (scene)
{
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
UpdateList.call(this);
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
destroy: function ()
{
this.shutdown();
this.scene = undefined;
}
});
PluginManager.register('UpdateListPlugin', UpdateListPlugin, 'updateList');
module.exports = UpdateListPlugin;

View file

@ -3,6 +3,7 @@ var Bob = require('./Bob');
var Class = require('../../utils/Class');
var Components = require('../components');
var DisplayList = require('../DisplayList');
var Frame = require('../../textures/Frame');
var GameObject = require('../GameObject');
/**
@ -41,7 +42,7 @@ var Blitter = new Class({
this.setTexture(texture, frame);
this.setPosition(x, y);
this.children = new DisplayList(this);
this.children = new DisplayList();
this.renderList = [];
@ -49,6 +50,7 @@ var Blitter = new Class({
},
// frame MUST be part of the Blitter texture
// and can be either a Frame object or a string
create: function (x, y, frame, visible, index)
{
if (visible === undefined) { visible = true; }
@ -58,7 +60,7 @@ var Blitter = new Class({
{
frame = this.frame;
}
else
else if (!(frame instanceof Frame))
{
frame = this.texture.get(frame);
}
@ -90,7 +92,7 @@ var Blitter = new Class({
// frame MUST be part of the Blitter texture
createMultiple: function (quantity, frame, visible)
{
if (frame === undefined) { frame = this.frame; }
if (frame === undefined) { frame = this.frame.name; }
if (visible === undefined) { visible = true; }
if (!Array.isArray(frame))

View file

@ -23,7 +23,10 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
ca = renderer.setAlpha(bob.alpha);
}
renderer.blitImage(bob.x, bob.y, bob.frame, camera);
// var x = src.x + bob.x + frame.x - cameraScrollX + ((frame.width) * (bob.flipX ? 1 : 0));
// var y = src.y + bob.y + frame.y - cameraScrollY + ((frame.height) * (bob.flipY ? 1 : 0));
renderer.blitImage(src.x + bob.x, src.y + bob.y, bob.frame, camera);
}
};

View file

@ -20,6 +20,20 @@ var Bob = new Class({
this.flipY = false;
},
setFrame: function (frame)
{
if (frame === undefined)
{
frame = this.parent.frame;
}
else
{
frame = this.parent.texture.get(frame);
}
return this;
},
resetFlip: function ()
{
this.flipX = false;
@ -33,6 +47,42 @@ var Bob = new Class({
this.frame = frame;
},
setFlipX: function (value)
{
this.flipX = value;
return this;
},
setFlipY: function (value)
{
this.flipY = value;
return this;
},
setFlip: function (x, y)
{
this.flipX = x;
this.flipY = y;
return this;
},
setVisible: function (value)
{
this.visible = value;
return this;
},
setAlpha: function (value)
{
this.alpha = value;
return this;
},
destroy: function ()
{
this.parent.dirty = true;

View file

@ -3,7 +3,9 @@
var GameObjects = {
DisplayList: require('./DisplayList'),
DisplayListPlugin: require('./DisplayListPlugin'),
UpdateList: require('./UpdateList'),
UpdateListPlugin: require('./UpdateListPlugin'),
GameObjectCreator: require('./GameObjectCreator'),
GameObjectFactory: require('./GameObjectFactory'),

View file

@ -38,9 +38,16 @@ var InputManager = new Class({
this.scale = { x: 1, y: 1 };
// If the top-most Scene in the Scene List receives an input it will stop input from
// propagating any lower down the scene list, i.e. if you have a UI Scene at the top
// and click something on it, that click will not then be passed down to any other
// Scene below. Disable this to have input events passed through all Scenes, all the time.
this.globalTopOnly = true;
this.ignoreEvents = false;
this.bounds;
// this._tempMatrix = new TransformMatrix();
this._tempPoint = { x: 0, y: 0 };
this._tempHitTest = [];
@ -85,6 +92,8 @@ var InputManager = new Class({
this.keyboard.update();
this.gamepad.update();
this.ignoreEvents = false;
var len = this.queue.length;
// Currently just 1 pointer supported

View file

@ -210,6 +210,8 @@ var InputPlugin = new Class({
// Contains ALL Game Objects currently over in the array
this.emit('pointerdown', pointer, currentlyOver);
var total = 0;
// Go through all objects the pointer was over and fire their events / callbacks
for (var i = 0; i < currentlyOver.length; i++)
{
@ -220,10 +222,14 @@ var InputPlugin = new Class({
continue;
}
total++;
gameObject.emit('pointerdown', pointer, gameObject.input.localX, gameObject.input.localY, pointer.camera);
this.emit('gameobjectdown', pointer, gameObject);
}
return total;
},
processDragEvents: function (pointer, time)
@ -231,7 +237,7 @@ var InputPlugin = new Class({
if (this._draggable.length === 0)
{
// There are no draggable items, so let's not even bother going further
return;
return 0;
}
var i;
@ -481,6 +487,8 @@ var InputPlugin = new Class({
pointer.dragState = 0;
}
return (pointer.dragState > 0);
},
processMoveEvents: function (pointer)
@ -489,6 +497,8 @@ var InputPlugin = new Class({
this.emit('pointermove', pointer, currentlyOver);
var total = 0;
// Go through all objects the pointer was over and fire their events / callbacks
for (var i = 0; i < currentlyOver.length; i++)
{
@ -499,6 +509,8 @@ var InputPlugin = new Class({
continue;
}
total++;
gameObject.emit('pointermove', pointer, gameObject.input.localX, gameObject.input.localY);
this.emit('gameobjectmove', pointer, gameObject);
@ -508,6 +520,8 @@ var InputPlugin = new Class({
break;
}
}
return total;
},
processOverOutEvents: function (pointer)
@ -611,6 +625,8 @@ var InputPlugin = new Class({
// Then sort it into display list order
this._over[pointer.id] = this.sortGameObjects(previouslyOver);
return previouslyOver.length;
},
processUpEvents: function (pointer)
@ -808,6 +824,13 @@ var InputPlugin = new Class({
return this;
},
setGlobalTopOnly: function (value)
{
this.manager.globalTopOnly = value;
return this;
},
setTopOnly: function (value)
{
this.topOnly = value;
@ -887,9 +910,27 @@ var InputPlugin = new Class({
return interactiveObjects.sort(this.sortHandlerIO.bind(this));
},
stopPropagation: function ()
{
if (this.manager.globalTopOnly)
{
this.manager.ignoreEvents = true;
}
return this;
},
update: function (time, delta)
{
var pointer = this.manager.activePointer;
var manager = this.manager;
// Another Scene above this one has already consumed the input events
if (manager.globalTopOnly && manager.ignoreEvents)
{
return;
}
var pointer = manager.activePointer;
var runUpdate = (pointer.dirty || this.pollRate === 0);
@ -921,16 +962,16 @@ var InputPlugin = new Class({
this._temp.splice(1);
}
this.processDragEvents(pointer, time);
var total = this.processDragEvents(pointer, time);
if (!pointer.wasTouch)
{
this.processOverOutEvents(pointer);
total += this.processOverOutEvents(pointer);
}
if (pointer.justDown)
{
this.processDownEvents(pointer);
total += this.processDownEvents(pointer);
}
if (pointer.justUp)
@ -940,7 +981,13 @@ var InputPlugin = new Class({
if (pointer.justMoved)
{
this.processMoveEvents(pointer);
total += this.processMoveEvents(pointer);
}
if (total > 0 && manager.globalTopOnly)
{
// We interacted with an event in this Scene, so block any Scenes below us from doing the same this frame
manager.ignoreEvents = true;
}
},

View file

@ -0,0 +1,34 @@
// XBox 360 controller
module.exports = {
UP: 12,
DOWN: 13,
LEFT: 14,
RIGHT: 15,
MENU: 16,
A: 0,
B: 1,
X: 2,
Y: 3,
LB: 4,
RB: 5,
LT: 6,
RT: 7,
BACK: 8,
START: 9,
LS: 10,
RS: 11,
LEFT_STICK_H: 0,
LEFT_STICK_V: 1,
RIGHT_STICK_H: 2,
RIGHT_STICK_V: 3
};

View file

@ -3,6 +3,7 @@
module.exports = {
DUALSHOCK_4: require('./Sony_PlayStation_DualShock_4'),
SNES_USB: require('./SNES_USB_Controller')
SNES_USB: require('./SNES_USB_Controller'),
XBOX_360: require('./XBox360_Controller')
};

View file

@ -1,4 +1,5 @@
module.exports = {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
@ -84,5 +85,9 @@ module.exports = {
PERIOD: 190,
FORWAD_SLASH: 191,
BACK_SLASH: 220,
QUOTES: 222
QUOTES: 222,
BACKTICK: 192,
OPEN_BRACKET: 219,
CLOSED_BRACKET: 221
};

View file

@ -170,8 +170,6 @@ var CanvasRenderer = new Class({
*/
render: function (scene, children, interpolationPercentage, camera)
{
// var w = scene.sys.width;
// var h = scene.sys.height;
var ctx = scene.sys.context;
var settings = scene.sys.settings;
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
@ -230,14 +228,13 @@ var CanvasRenderer = new Class({
{
child.mask.postRenderCanvas(this, child, camera);
}
}
// Call the Scene.render function
scene.render.call(scene, ctx, interpolationPercentage);
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Emit a scene render event?
// scene.sys.events.emit('render', scene, ctx, camera);
if (camera._fadeAlpha > 0 || camera._flashAlpha > 0)
{
ctx.globalCompositeOperation = 'source-over';
@ -260,18 +257,10 @@ var CanvasRenderer = new Class({
{
ctx.restore();
}
// Blast it to the Game Canvas (if needed)
// if (settings.renderToTexture)
// {
// this.gameContext.drawImage(scene.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h);
// }
},
postRender: function ()
{
// console.log('%c render end ', 'color: #ffffff; background: #ff0000;');
var ctx = this.gameContext;
ctx.globalAlpha = 1;
@ -285,8 +274,6 @@ var CanvasRenderer = new Class({
this.snapshotCallback(CanvasSnapshot(this.gameCanvas, this.snapshotType, this.snapshotEncoder));
this.snapshotCallback = null;
}
// Add Post-render hook
},
snapshot: function (callback, type, encoderOptions)

View file

@ -97,6 +97,8 @@ var BlitterBatch = new Class({
var cameraScrollY = camera.scrollY * blitter.scrollFactorY;
var batchCount = Math.ceil(length / 2000);
var batchOffset = 0;
var blitterX = blitter.x;
var blitterX = blitter.y;
orthoViewMatrix[0] = +2.0 / this.width;
orthoViewMatrix[5] = -2.0 / this.height;
@ -119,8 +121,8 @@ var BlitterBatch = new Class({
var flipY = bob.flipY;
var width = frame.width * (flipX ? -1.0 : 1.0);
var height = frame.height * (flipY ? -1.0 : 1.0);
var x = bob.x + frame.x - cameraScrollX + (width * ((flipX) ? 1.0 : 0.0));
var y = bob.y + frame.y - cameraScrollY + (height * ((flipY) ? 1.0 : 0.0));
var x = blitterX + bob.x + frame.x - cameraScrollX + (width * ((flipX) ? 1.0 : 0.0));
var y = blitterY + bob.y + frame.y - cameraScrollY + (height * ((flipY) ? 1.0 : 0.0));
var xw = x + width;
var yh = y + height;
var tx = x * a + y * c + e;

File diff suppressed because it is too large Load diff

View file

@ -33,97 +33,20 @@ var ScenePlugin = new Class({
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
preUpdate: function ()
{
var len = this._queue.length;
if (len === 0)
{
return;
}
var manager = this.manager;
// Process the queue
for (var i = 0; i < len; i++)
{
var action = this._queue[i];
switch (action.type)
{
case 'add':
manager.add(action.key, action.data, action.autoStart);
break;
case 'start':
manager.stop(this.key);
manager.start(action.key, action.data);
break;
case 'launch':
manager.start(action.key, action.data);
break;
case 'pause':
manager.pause(action.key);
break;
case 'resume':
manager.resume(action.key);
break;
case 'stop':
manager.stop(action.key);
break;
case 'swap':
manager.swap(this.key, action.key);
break;
case 'moveUp':
manager.moveUp(this.key);
break;
case 'moveDown':
manager.moveDown(this.key);
break;
case 'bringToTop':
manager.bringToTop(this.key);
break;
case 'sendToBack':
manager.sendToBack(this.key);
break;
case 'swapPosition':
manager.swapPosition(this.key, action.key);
break;
case 'sleep':
manager.sleep(action.key);
break;
case 'wake':
manager.wake(action.key);
break;
}
}
this._queue.length = 0;
},
// Shutdown this Scene and run the given one
start: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'start', key: key, data: data });
if (key !== this.key)
{
this.manager.stop(this.key);
this.manager.start(key);
}
return this;
},
@ -131,7 +54,7 @@ var ScenePlugin = new Class({
// 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, sceneConfig, autoStart)
{
this._queue.push({ type: 'add', key: key, data: sceneConfig, autoStart: autoStart });
this.manager.add(key, sceneConfig, autoStart);
return this;
},
@ -139,9 +62,10 @@ var ScenePlugin = new Class({
// Launch the given Scene and run it in parallel with this one
launch: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'launch', key: key, data: data });
if (key && key !== this.key)
{
this.manager.start(key);
}
return this;
},
@ -151,7 +75,7 @@ var ScenePlugin = new Class({
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'pause', key: key });
this.manager.pause(key);
return this;
},
@ -161,7 +85,7 @@ var ScenePlugin = new Class({
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'resume', key: key });
this.manager.resume(key);
return this;
},
@ -169,7 +93,9 @@ var ScenePlugin = new Class({
// Makes the Scene sleep (no update, no render) but doesn't shutdown
sleep: function (key)
{
this._queue.push({ type: 'sleep', key: key });
if (key === undefined) { key = this.key; }
this.manager.sleep(key);
return this;
},
@ -177,15 +103,20 @@ var ScenePlugin = new Class({
// Makes the Scene wake-up (starts update and render)
wake: function (key)
{
this._queue.push({ type: 'wake', key: key });
if (key === undefined) { key = this.key; }
this.manager.wake(key);
return this;
},
// Makes this Scene sleep then starts the Scene given
swap: function (key)
switch: function (key)
{
this._queue.push({ type: 'swap', key: key });
if (key !== this.key)
{
this.manager.switch(this.key, key);
}
return this;
},
@ -195,7 +126,14 @@ var ScenePlugin = new Class({
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'stop', key: key });
this.manager.stop(key);
return this;
},
setActive: function (value)
{
this.settings.active = value;
return this;
},
@ -207,38 +145,11 @@ var ScenePlugin = new Class({
return this;
},
swapPosition: function (key)
isSleeping: function (key)
{
this._queue.push({ type: 'swapPosition', key: key });
},
if (key === undefined) { key = this.key; }
moveUp: function ()
{
this._queue.push({ type: 'moveUp' });
},
moveDown: function ()
{
this._queue.push({ type: 'moveDown' });
},
bringToTop: function ()
{
this._queue.push({ type: 'bringToTop' });
},
sendToBack: function ()
{
this._queue.push({ type: 'sendToBack' });
},
get: function (key)
{
return this.manager.getScene(key);
},
transitionTo: function (key, duration)
{
return this.manager.isSleeping(key);
},
isActive: function (key)
@ -248,6 +159,64 @@ var ScenePlugin = new Class({
return this.manager.isActive(key);
},
isVisible: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isVisible(key);
},
swapPosition: function (key)
{
if (key && key !== this.key)
{
this.manager.swapPosition(this.key, key);
}
return this;
},
moveUp: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveUp(key);
return this;
},
moveDown: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveDown(key);
return this;
},
bringToTop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.bringToTop(key);
return this;
},
sendToBack: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sendToBack(key);
return this;
},
get: function (key)
{
return this.manager.getScene(key);
},
shutdown: function ()
{
// TODO

View file

@ -21,8 +21,6 @@ var Settings = {
status: CONST.PENDING,
op: CONST.BOOT,
key: GetValue(config, 'key', ''),
active: GetValue(config, 'active', false),
visible: GetValue(config, 'visible', true),
@ -53,19 +51,7 @@ var Settings = {
// Plugins
plugins: GetValue(config, 'plugins', false),
// Scene Render Settings (applies only to this Scene)
scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT),
roundPixels: GetValue(config, 'roundPixels', false),
dirtyRender: GetValue(config, 'dirtyRender', false),
renderToTexture: GetValue(config, 'renderToTexture', false),
// The following only apply if renderToTexture is true
autoResize: GetValue(config, 'autoResize', false)
plugins: GetValue(config, 'plugins', false)
};
}

View file

@ -1,4 +1,5 @@
var Class = require('../utils/Class');
var CONST = require('./const');
var CoreScenePlugins = require('../CoreScenePlugins');
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
var GetScenePlugins = require('./GetScenePlugins');
@ -19,8 +20,7 @@ var Systems = new Class({
this.settings = Settings.create(config);
// Set by the SceneManager - a reference to the Scene canvas / context
// A handy reference to the Scene canvas / context
this.canvas;
this.context;
@ -46,8 +46,13 @@ var Systems = new Class({
init: function (game)
{
this.settings.status = CONST.INIT;
this.game = game;
this.canvas = game.canvas;
this.context = game.context;
var pluginManager = game.plugins;
this.plugins = pluginManager;
@ -79,11 +84,6 @@ var Systems = new Class({
{
this.events.emit('preupdate', time, delta);
if (!this.settings.active)
{
return;
}
this.events.emit('update', time, delta);
this.scene.update.call(this.scene, time, delta);
@ -91,18 +91,15 @@ var Systems = new Class({
this.events.emit('postupdate', time, delta);
},
render: function (interpolation, renderer)
render: function (renderer)
{
if (!this.settings.visible)
{
return;
}
var displayList = this.displayList;
displayList.process();
this.cameras.render(renderer, displayList, interpolation);
this.cameras.render(renderer, displayList);
this.events.emit('render', renderer);
},
// Force a sort of the display list on the next render
@ -120,25 +117,31 @@ var Systems = new Class({
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
pause: function ()
{
// Was paused by the SceneManager
if (this.settings.active)
{
this.settings.status = CONST.PAUSED;
this.settings.active = false;
this.settings.active = false;
this.events.emit('pause', this);
this.events.emit('pause', this);
}
},
resume: function ()
{
// Was resumed by the SceneManager
if (!this.settings.active)
{
this.settings.status = CONST.RUNNING;
this.settings.active = true;
this.settings.active = true;
this.events.emit('resume', this);
this.events.emit('resume', this);
}
},
sleep: function ()
{
// Was sent to sleep by the SceneManager
this.settings.status = CONST.SLEEPING;
this.settings.active = false;
this.settings.visible = false;
@ -148,7 +151,7 @@ var Systems = new Class({
wake: function ()
{
// Was woken up by the SceneManager
this.settings.status = CONST.RUNNING;
this.settings.active = true;
this.settings.visible = true;
@ -156,9 +159,43 @@ var Systems = new Class({
this.events.emit('wake', this);
},
isSleeping: function ()
{
return (this.settings.status === CONST.SLEEPING);
},
isActive: function ()
{
return (this.settings.status === CONST.RUNNING);
},
isVisible: function ()
{
return this.settings.visible;
},
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
setActive: function (value)
{
if (value)
{
return this.resume();
}
else
{
return this.pause();
}
},
start: function (data)
{
// Was started by the SceneManager
this.settings.status = CONST.START;
this.settings.data = data;
@ -170,7 +207,7 @@ var Systems = new Class({
shutdown: function ()
{
// Was stopped by the SceneManager
this.settings.status = CONST.SHUTDOWN;
this.settings.active = false;
this.settings.visible = false;
@ -180,6 +217,8 @@ var Systems = new Class({
destroy: function ()
{
this.settings.status = CONST.DESTROYED;
this.events.emit('destroy', this);
}

View file

@ -2,14 +2,13 @@
module.exports = {
PENDING: 0,
INSTALLED: 1,
BOOT: 0,
INIT: 1,
PRELOAD: 2,
CREATE: 3,
UPDATE: 4,
RENDER: 5,
SHUTDOWN: 6
START: 2,
LOADING: 3,
RUNNING: 4,
PAUSED: 5,
SLEEPING: 6,
SHUTDOWN: 7,
DESTROYED: 8
};

View file

@ -77,7 +77,7 @@ var Texture = new Class({
get: function (name)
{
if (name === undefined || name === null)
if (name === undefined || name === null || (typeof name !== 'string' && typeof name !== 'number'))
{
name = (this.frameTotal === 1) ? '__BASE' : this.firstFrame;
}