Merge with master

This commit is contained in:
Felipe Alfonso 2018-01-17 18:30:39 -03:00
commit 4983b393e3
93 changed files with 782 additions and 600 deletions

9
src/animations/index.js Normal file
View file

@ -0,0 +1,9 @@
// Phaser.Animations
module.exports = {
Animation: require('./Animation'),
AnimationFrame: require('./AnimationFrame'),
AnimationManager: require('./AnimationManager'),
};

8
src/cache/index.js vendored Normal file
View file

@ -0,0 +1,8 @@
// Phaser.Cache
module.exports = {
BaseCache: require('./BaseCache'),
CacheManager: require('./CacheManager')
};

View file

@ -116,25 +116,6 @@ var CameraManager = new Class({
}, },
*/ */
destroy: function ()
{
this.main = undefined;
for (var i = 0; i < this.cameras.length; i++)
{
this.cameras[i].destroy();
}
for (i = 0; i < this.cameraPool.length; i++)
{
this.cameraPool[i].destroy();
}
this.cameras = [];
this.cameraPool = [];
this.scene = undefined;
},
/* /*
{ {
cameras: [ cameras: [
@ -246,7 +227,7 @@ var CameraManager = new Class({
} }
}, },
removeCamera: function (camera) remove: function (camera)
{ {
var cameraIndex = this.cameras.indexOf(camera); var cameraIndex = this.cameras.indexOf(camera);
@ -298,6 +279,25 @@ var CameraManager = new Class({
shutdown: function () shutdown: function ()
{ {
},
destroy: function ()
{
this.main = undefined;
for (var i = 0; i < this.cameras.length; i++)
{
this.cameras[i].destroy();
}
for (i = 0; i < this.cameraPool.length; i++)
{
this.cameraPool[i].destroy();
}
this.cameras = [];
this.cameraPool = [];
this.scene = undefined;
} }
}); });

View file

@ -3,7 +3,7 @@
var Class = require('../../utils/Class'); var Class = require('../../utils/Class');
var CubicBezierCurve = require('../cubicbezier/CubicBezierCurve'); var CubicBezierCurve = require('../cubicbezier/CubicBezierCurve');
var EllipseCurve = require('../ellipse/EllipseCurve'); var EllipseCurve = require('../ellipse/EllipseCurve');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../../gameobjects/GameObjectFactory');
var LineCurve = require('../line/LineCurve'); var LineCurve = require('../line/LineCurve');
var MovePathTo = require('./MoveTo'); var MovePathTo = require('./MoveTo');
var Rectangle = require('../../geom/rectangle/Rectangle'); var Rectangle = require('../../geom/rectangle/Rectangle');

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var StableSort = require('../../utils/array/StableSort'); var StableSort = require('../utils/array/StableSort');
var PluginManager = require('../../plugins/PluginManager'); var PluginManager = require('../plugins/PluginManager');
var DisplayList = new Class({ var DisplayList = new Class({
@ -13,7 +13,7 @@ var DisplayList = new Class({
this.systems = scene.sys; this.systems = scene.sys;
this.mapping = 'add'; this.mapping = 'children';
this.systems.events.on('boot', this.boot, this); this.systems.events.on('boot', this.boot, this);

View file

@ -226,7 +226,7 @@ var GameObject = new Class({
*/ */
setInteractive: function (shape, callback) setInteractive: function (shape, callback)
{ {
this.scene.sys.inputManager.enable(this, shape, callback); this.scene.sys.input.enable(this, shape, callback);
return this; return this;
}, },
@ -282,25 +282,27 @@ var GameObject = new Class({
this.preDestroy.call(this); this.preDestroy.call(this);
} }
this.scene.sys.displayList.remove(this); var sys = this.scene.sys;
this.scene.sys.updateList.remove(this);
sys.displayList.remove(this);
sys.updateList.remove(this);
if (this.input) if (this.input)
{ {
this.scene.sys.inputManager.clear(this); sys.input.clear(this);
this.input = undefined; this.input = undefined;
} }
// TODO Keep a reference to the manager in Body, so body can remove itself, not via System // TODO Keep a reference to the manager in Body, so body can remove itself, not via System
if (this.body) if (this.body)
{ {
this.scene.sys.physicsManager.remove(this); sys.physicsManager.remove(this);
this.body = undefined; this.body = undefined;
} }
// Tell the Scene to re-sort the children // Tell the Scene to re-sort the children
this.scene.sys.queueDepthSort(); sys.queueDepthSort();
this.active = false; this.active = false;
this.visible = false; this.visible = false;

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var PluginManager = require('../../plugins/PluginManager'); var PluginManager = require('../plugins/PluginManager');
var GameObjectCreator = new Class({ var GameObjectCreator = new Class({

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var PluginManager = require('../../plugins/PluginManager'); var PluginManager = require('../plugins/PluginManager');
var GameObjectFactory = new Class({ var GameObjectFactory = new Class({
@ -12,7 +12,7 @@ var GameObjectFactory = new Class({
this.systems = scene.sys; this.systems = scene.sys;
this.mapping = 'time'; this.mapping = 'add';
this.systems.events.on('boot', this.boot, this); this.systems.events.on('boot', this.boot, this);

View file

@ -1,7 +1,6 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var PluginManager = require('../../plugins/PluginManager'); var PluginManager = require('../plugins/PluginManager');
// TODO - Extend from ProcessQueue
var UpdateList = new Class({ var UpdateList = new Class({
initialize: initialize:
@ -12,7 +11,7 @@ var UpdateList = new Class({
this.systems = scene.sys; this.systems = scene.sys;
this.mapping = 'children'; this.mapping = null;
this.systems.events.on('boot', this.boot, this); this.systems.events.on('boot', this.boot, this);

View file

@ -1,6 +1,6 @@
var BitmapText = require('./DynamicBitmapText'); var BitmapText = require('./DynamicBitmapText');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var DynamicBitmapText = require('./DynamicBitmapText'); var DynamicBitmapText = require('./DynamicBitmapText');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,6 +1,6 @@
var BitmapText = require('./BitmapText'); var BitmapText = require('./BitmapText');
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var GetValue = require('../../../utils/object/GetValue'); var GetValue = require('../../../utils/object/GetValue');

View file

@ -1,5 +1,5 @@
var BitmapText = require('./BitmapText'); var BitmapText = require('./BitmapText');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -2,7 +2,7 @@ var BlitterRender = require('./BlitterRender');
var Bob = require('./Bob'); var Bob = require('./Bob');
var Class = require('../../utils/Class'); var Class = require('../../utils/Class');
var Components = require('../components'); var Components = require('../components');
var DisplayList = require('../../scene/plugins/DisplayList'); var DisplayList = require('../DisplayList');
var GameObject = require('../GameObject'); var GameObject = require('../GameObject');
/** /**

View file

@ -1,6 +1,6 @@
var Blitter = require('./Blitter'); var Blitter = require('./Blitter');
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Blitter = require('./Blitter'); var Blitter = require('./Blitter');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,13 +1,10 @@
var Class = require('../../utils/Class'); var Class = require('../../utils/Class');
var Components = require('../components'); var Components = require('../components');
var DataProxy = require('../components/DataProxy'); var DataProxy = require('../components/DataProxy');
var DisplayList = require('../../scene/plugins/DisplayList');
var TransformMatrix = require('../components/TransformMatrix'); var TransformMatrix = require('../components/TransformMatrix');
var Container = new Class({ var Container = new Class({
// Extends: DisplayList,
// Mixins: [ // Mixins: [
// Components.Visible, // Components.Visible,
// SpriteRender // SpriteRender
@ -17,9 +14,6 @@ var Container = new Class({
function Container (scene, x, y) function Container (scene, x, y)
{ {
// this.list = children
// DisplayList.call(this, scene);
this.scene = scene; this.scene = scene;
this.type = 'Container'; this.type = 'Container';

View file

@ -1,5 +1,5 @@
var Container = require('./Container'); var Container = require('./Container');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Container = require('./Container'); var Container = require('./Container');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -261,6 +261,16 @@ var Graphics = new Class({
fillPoint: function (x, y, size) fillPoint: function (x, y, size)
{ {
if (!size || size < 1)
{
size = 1;
}
else
{
x -= (size / 2);
y -= (size / 2);
}
this.commandBuffer.push( this.commandBuffer.push(
Commands.FILL_RECT, Commands.FILL_RECT,
x, y, size, size x, y, size, size
@ -429,6 +439,26 @@ var Graphics = new Class({
return this.strokePoints(points, true); return this.strokePoints(points, true);
}, },
fillEllipseShape: function (ellipse, smoothness)
{
if (smoothness === undefined) { smoothness = 32; }
var points = ellipse.getPoints(smoothness);
return this.fillPoints(points, true);
},
fillEllipse: function (x, y, width, height, smoothness)
{
if (smoothness === undefined) { smoothness = 32; }
var ellipse = new Ellipse(x, y, width, height);
var points = ellipse.getPoints(smoothness);
return this.fillPoints(points, true);
},
// ARC // ARC

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var Graphics = require('./Graphics'); var Graphics = require('./Graphics');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Graphics = require('./Graphics'); var Graphics = require('./Graphics');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var Group = require('./Group'); var Group = require('./Group');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Group = require('./Group'); var Group = require('./Group');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Image = require('./Image'); var Image = require('./Image');

View file

@ -1,5 +1,5 @@
var Image = require('./Image'); var Image = require('./Image');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -2,6 +2,11 @@
var GameObjects = { var GameObjects = {
DisplayList: require('./DisplayList'),
UpdateList: require('./UpdateList'),
GameObjectCreator: require('./GameObjectCreator'),
GameObjectFactory: require('./GameObjectFactory'),
Components: require('./components'), Components: require('./components'),
BitmapText: require('./bitmaptext/static/BitmapText'), BitmapText: require('./bitmaptext/static/BitmapText'),

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var LightLayer = require('./LightLayer'); var LightLayer = require('./LightLayer');

View file

@ -1,5 +1,5 @@
var LightLayer = require('./LightLayer'); var LightLayer = require('./LightLayer');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
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 Mesh = require('./Mesh'); var Mesh = require('./Mesh');

View file

@ -1,5 +1,5 @@
var Mesh = require('./Mesh'); var Mesh = require('./Mesh');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetFastValue = require('../../utils/object/GetFastValue'); var GetFastValue = require('../../utils/object/GetFastValue');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var ParticleEmitterManager = require('./ParticleEmitterManager'); var ParticleEmitterManager = require('./ParticleEmitterManager');

View file

@ -1,5 +1,5 @@
var ParticleEmitterManager = require('./ParticleEmitterManager'); var ParticleEmitterManager = require('./ParticleEmitterManager');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,5 +1,5 @@
var PathFollower = require('./PathFollower'); var PathFollower = require('./PathFollower');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Quad = require('./Quad'); var Quad = require('./Quad');

View file

@ -1,5 +1,5 @@
var Quad = require('./Quad'); var Quad = require('./Quad');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,6 +1,6 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Sprite = require('./Sprite'); var Sprite = require('./Sprite');

View file

@ -1,5 +1,5 @@
var Sprite = require('./Sprite'); var Sprite = require('./Sprite');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,6 +1,6 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Sprite3D = require('./Sprite3D'); var Sprite3D = require('./Sprite3D');

View file

@ -1,5 +1,5 @@
var Sprite3D = require('./Sprite3D'); var Sprite3D = require('./Sprite3D');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../../BuildGameObject'); var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var Text = require('./Text'); var Text = require('./Text');

View file

@ -1,5 +1,5 @@
var Text = require('./Text'); var Text = require('./Text');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var ParseToTilemap = require('./ParseToTilemap'); var ParseToTilemap = require('./ParseToTilemap');
// When registering a factory function 'this' refers to the GameObjectCreator context. // When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,4 +1,4 @@
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
var ParseToTilemap = require('./ParseToTilemap'); var ParseToTilemap = require('./ParseToTilemap');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.

View file

@ -17,7 +17,6 @@ var DynamicTilemapLayer = new Class({
Components.RenderTarget, Components.RenderTarget,
Components.ScaleMode, Components.ScaleMode,
Components.Size, Components.Size,
Components.Texture,
Components.Transform, Components.Transform,
Components.Visible, Components.Visible,
Components.ScrollFactor, Components.ScrollFactor,
@ -90,9 +89,7 @@ var DynamicTilemapLayer = new Class({
this.culledTiles = []; this.culledTiles = [];
this.setAlpha(this.layer.alpha); this.setAlpha(this.layer.alpha);
this.setTexture(tileset.image.key);
this.setPosition(x, y); this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin(); this.setOrigin();
this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height);
}, },

View file

@ -11,7 +11,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpol
var renderTiles = gameObject.culledTiles; var renderTiles = gameObject.culledTiles;
var length = renderTiles.length; var length = renderTiles.length;
var image = gameObject.frame.source.image; var image = gameObject.tileset.image.getSourceImage();
var tileset = this.tileset; var tileset = this.tileset;
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX; var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;

View file

@ -12,7 +12,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpola
var renderTiles = gameObject.culledTiles; var renderTiles = gameObject.culledTiles;
var length = renderTiles.length; var length = renderTiles.length;
var batch = renderer.spriteBatch; var batch = renderer.spriteBatch;
var texture = gameObject.texture.source[0].glTexture; var texture = gameObject.tileset.image.get().source.glTexture;
var textureWidth = texture.width; var textureWidth = texture.width;
var textureHeight = texture.height; var textureHeight = texture.height;
var tileset = this.tileset; var tileset = this.tileset;

View file

@ -18,7 +18,6 @@ var StaticTilemapLayer = new Class({
Components.RenderTarget, Components.RenderTarget,
Components.ScaleMode, Components.ScaleMode,
Components.Size, Components.Size,
Components.Texture,
Components.Transform, Components.Transform,
Components.Visible, Components.Visible,
Components.ScrollFactor, Components.ScrollFactor,
@ -99,9 +98,7 @@ var StaticTilemapLayer = new Class({
this.vertexCount = 0; this.vertexCount = 0;
this.setAlpha(this.layer.alpha); this.setAlpha(this.layer.alpha);
this.setTexture(tileset.image.key);
this.setPosition(x, y); this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin(); this.setOrigin();
this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height);
@ -113,7 +110,6 @@ var StaticTilemapLayer = new Class({
*/ */
contextRestore: function (renderer) contextRestore: function (renderer)
{ {
this.tileTexture = null;
this.dirty = true; this.dirty = true;
this.vbo = null; this.vbo = null;
this.gl = renderer.gl; this.gl = renderer.gl;
@ -131,8 +127,8 @@ var StaticTilemapLayer = new Class({
var tileset = this.tileset; var tileset = this.tileset;
var mapWidth = this.layer.width; var mapWidth = this.layer.width;
var mapHeight = this.layer.height; var mapHeight = this.layer.height;
var width = this.texture.source[0].width; var width = tileset.image.get().width;
var height = this.texture.source[0].height; var height = tileset.image.get().height;
var mapData = this.layer.data; var mapData = this.layer.data;
var tile; var tile;

View file

@ -12,10 +12,9 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, gameObject, interpola
var renderTiles = gameObject.culledTiles; var renderTiles = gameObject.culledTiles;
var tileset = this.tileset; var tileset = this.tileset;
var frame = gameObject.frame;
var ctx = renderer.gameContext; var ctx = renderer.gameContext;
var tileCount = renderTiles.length; var tileCount = renderTiles.length;
var image = frame.source.image; var image = tileset.image.getSourceImage();
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX; var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY; var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY;

View file

@ -8,10 +8,10 @@ var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPerc
} }
var gameObject = src; var gameObject = src;
var frame = gameObject.frame;
var gl = gameObject.gl; var gl = gameObject.gl;
var frame = gameObject.tileset.image.get();
renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget); renderer.setRenderer(gameObject.tilemapRenderer, frame.source.glTexture, gameObject.renderTarget);
gameObject.tilemapRenderer.bind(); gameObject.tilemapRenderer.bind();
gameObject.upload(camera); gameObject.upload(camera);

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject'); var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var TileSprite = require('./TileSprite'); var TileSprite = require('./TileSprite');

View file

@ -1,5 +1,5 @@
var TileSprite = require('./TileSprite'); var TileSprite = require('./TileSprite');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Zone = require('./Zone'); var Zone = require('./Zone');

View file

@ -1,5 +1,5 @@
var Zone = require('./Zone'); var Zone = require('./Zone');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context. // When registering a factory function 'this' refers to the GameObjectFactory context.
// //

View file

@ -10,8 +10,8 @@
*/ */
var Circumference = function (ellipse) var Circumference = function (ellipse)
{ {
var rx = ellipse.width; var rx = ellipse.width / 2;
var ry = ellipse.height; var ry = ellipse.height / 2;
var h = Math.pow((rx - ry), 2) / Math.pow((rx + ry), 2); var h = Math.pow((rx - ry), 2) / Math.pow((rx + ry), 2);
return (Math.PI * (rx + ry)) * (1 + ((3 * h) / (10 + Math.sqrt(4 - (3 * h))))); return (Math.PI * (rx + ry)) * (1 + ((3 * h) / (10 + Math.sqrt(4 - (3 * h)))));

View file

@ -16,14 +16,14 @@ var Contains = function (ellipse, x, y)
{ {
return false; return false;
} }
// Normalize the coords to an ellipse with center 0,0 and a radius of 0.5 // Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
var normx = ((x - ellipse.x) / ellipse.width) - 0.5; var normx = ((x - ellipse.x) / ellipse.width);
var normy = ((y - ellipse.y) / ellipse.height) - 0.5; var normy = ((y - ellipse.y) / ellipse.height);
normx *= normx; normx *= normx;
normy *= normy; normy *= normy;
return (normx + normy < 0.25); return (normx + normy < 0.25);
}; };

View file

@ -15,8 +15,8 @@ var GetBounds = function (ellipse, out)
{ {
if (out === undefined) { out = new Rectangle(); } if (out === undefined) { out = new Rectangle(); }
out.x = ellipse.x - ellipse.width; out.x = ellipse.left;
out.y = ellipse.y - ellipse.height; out.y = ellipse.top;
out.width = ellipse.width; out.width = ellipse.width;
out.height = ellipse.height; out.height = ellipse.height;

View file

@ -10,6 +10,7 @@ var Rectangle = require('../geom/rectangle/Rectangle');
var RectangleContains = require('../geom/rectangle/Contains'); var RectangleContains = require('../geom/rectangle/Contains');
var Triangle = require('../geom/triangle/Triangle'); var Triangle = require('../geom/triangle/Triangle');
var TriangleContains = require('../geom/triangle/Contains'); var TriangleContains = require('../geom/triangle/Contains');
var PluginManager = require('../plugins/PluginManager');
// Drag Events // Drag Events
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
@ -29,6 +30,12 @@ var InputPlugin = new Class({
// The Scene that owns this plugin // The Scene that owns this plugin
this.scene = scene; this.scene = scene;
this.systems = scene.sys;
this.mapping = 'input';
this.systems.events.on('boot', this.boot, this);
// InputManager // InputManager
this.manager = scene.sys.game.input; this.manager = scene.sys.game.input;
@ -87,36 +94,21 @@ var InputPlugin = new Class({
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ]; this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ];
}, },
activePointer: { boot: function ()
{
this.systems.inject(this);
get: function () this.systems.events.on('preupdate', this.preUpdate, this);
{ this.systems.events.on('update', this.update, this);
return this.manager.activePointer; this.systems.events.on('shutdown', this.shutdown, this);
} this.systems.events.on('destroy', this.destroy, this);
this.cameras = this.systems.cameras;
this.displayList = this.systems.displayList;
}, },
// The x/y coordinates of the ActivePointer based on the first camera in the camera list. preUpdate: function ()
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {
get: function ()
{
return this.manager.activePointer.x;
}
},
y: {
get: function ()
{
return this.manager.activePointer.y;
}
},
begin: function ()
{ {
var removeList = this._pendingRemoval; var removeList = this._pendingRemoval;
var insertList = this._pendingInsertion; var insertList = this._pendingInsertion;
@ -156,13 +148,6 @@ var InputPlugin = new Class({
this._list = current.concat(insertList.splice(0)); this._list = current.concat(insertList.splice(0));
}, },
boot: function ()
{
this.cameras = this.scene.sys.cameras;
this.displayList = this.scene.sys.displayList;
},
clear: function (gameObject) clear: function (gameObject)
{ {
var input = gameObject.input; var input = gameObject.input;
@ -209,7 +194,7 @@ var InputPlugin = new Class({
// Get a list of all objects that can be seen by the camera below the pointer in the scene and store in 'output' array. // Get a list of all objects that can be seen by the camera below the pointer in the scene and store in 'output' array.
// All objects in this array are input enabled, as checked by the hitTest method, so we don't need to check later on as well. // All objects in this array are input enabled, as checked by the hitTest method, so we don't need to check later on as well.
return this.manager.hitTest(this._list, pointer.x, pointer.y, camera); return this.manager.hitTest(pointer.x, pointer.y, this._list, camera);
} }
else else
{ {
@ -988,8 +973,39 @@ var InputPlugin = new Class({
this.keyboard = undefined; this.keyboard = undefined;
this.mouse = undefined; this.mouse = undefined;
this.gamepad = undefined; this.gamepad = undefined;
} },
activePointer: {
get: function ()
{
return this.manager.activePointer;
}
},
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {
get: function ()
{
return this.manager.activePointer.x;
}
},
y: {
get: function ()
{
return this.manager.activePointer.y;
}
},
}); });
PluginManager.register('input', InputPlugin);
module.exports = InputPlugin; module.exports = InputPlugin;

View file

@ -3,6 +3,8 @@
module.exports = { module.exports = {
Gamepad: require('./gamepad'), Gamepad: require('./gamepad'),
InputManager: require('./InputManager'),
InputPlugin: require('./InputPlugin'),
InteractiveObject: require('./InteractiveObject'), InteractiveObject: require('./InteractiveObject'),
Keyboard: require('./keyboard'), Keyboard: require('./keyboard'),
Mouse: require('./mouse'), Mouse: require('./mouse'),

View file

@ -1,26 +1,28 @@
var BaseLoader = require('../../loader/BaseLoader'); var BaseLoader = require('./BaseLoader');
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var CONST = require('../../loader/const'); var CONST = require('./const');
var NumberArray = require('../../utils/array/NumberArray'); var NumberArray = require('../utils/array/NumberArray');
var PluginManager = require('../plugins/PluginManager');
var AnimationJSONFile = require('../../loader/filetypes/AnimationJSONFile'); // TODO - Injection mapped
var AtlasJSONFile = require('../../loader/filetypes/AtlasJSONFile'); var AnimationJSONFile = require('./filetypes/AnimationJSONFile');
var AudioFile = require('../../loader/filetypes/AudioFile'); var AtlasJSONFile = require('./filetypes/AtlasJSONFile');
var BinaryFile = require('../../loader/filetypes/BinaryFile'); var AudioFile = require('./filetypes/AudioFile');
var BitmapFontFile = require('../../loader/filetypes/BitmapFontFile'); var BinaryFile = require('./filetypes/BinaryFile');
var GLSLFile = require('../../loader/filetypes/GLSLFile'); var BitmapFontFile = require('./filetypes/BitmapFontFile');
var HTMLFile = require('../../loader/filetypes/HTMLFile'); var GLSLFile = require('./filetypes/GLSLFile');
var ImageFile = require('../../loader/filetypes/ImageFile'); var HTMLFile = require('./filetypes/HTMLFile');
var JSONFile = require('../../loader/filetypes/JSONFile'); var ImageFile = require('./filetypes/ImageFile');
var ScriptFile = require('../../loader/filetypes/ScriptFile'); var JSONFile = require('./filetypes/JSONFile');
var SpriteSheet = require('../../loader/filetypes/SpriteSheet'); var ScriptFile = require('./filetypes/ScriptFile');
var SVGFile = require('../../loader/filetypes/SVGFile'); var SpriteSheet = require('./filetypes/SpriteSheet');
var TextFile = require('../../loader/filetypes/TextFile'); var SVGFile = require('./filetypes/SVGFile');
var TilemapCSVFile = require('../../loader/filetypes/TilemapCSVFile'); var TextFile = require('./filetypes/TextFile');
var TilemapJSONFile = require('../../loader/filetypes/TilemapJSONFile'); var TilemapCSVFile = require('./filetypes/TilemapCSVFile');
var UnityAtlasFile = require('../../loader/filetypes/UnityAtlasFile'); var TilemapJSONFile = require('./filetypes/TilemapJSONFile');
var WavefrontFile = require('../../loader/filetypes/WavefrontFile'); var UnityAtlasFile = require('./filetypes/UnityAtlasFile');
var XMLFile = require('../../loader/filetypes/XMLFile'); var WavefrontFile = require('./filetypes/WavefrontFile');
var XMLFile = require('./filetypes/XMLFile');
var Loader = new Class({ var Loader = new Class({
@ -32,9 +34,23 @@ var Loader = new Class({
{ {
BaseLoader.call(this, scene); BaseLoader.call(this, scene);
this.systems = scene.sys;
this.mapping = 'load';
this.systems.events.on('boot', this.boot, this);
this._multilist = {}; this._multilist = {};
}, },
boot: function ()
{
this.systems.inject(this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
// key can be either a string, an object or an array of objects // key can be either a string, an object or an array of objects
image: function (key, url, xhrSettings) image: function (key, url, xhrSettings)
@ -294,8 +310,15 @@ var Loader = new Class({
} }
return entry; return entry;
},
shutdown: function ()
{
} }
}); });
PluginManager.register('load', Loader);
module.exports = Loader; module.exports = Loader;

9
src/loader/index.js Normal file
View file

@ -0,0 +1,9 @@
// Phaser.Loader
module.exports = {
BaseLoader: require('./BaseLoader'),
File: require('./File'),
LoaderPlugin: require('./Loader')
};

View file

@ -8,46 +8,29 @@ var Extend = require('./utils/object/Extend');
var Phaser = { var Phaser = {
Actions: require('./actions/'), Actions: require('./actions/'),
Animation: require('./animations/'),
Create: require('./create/'), Cache: require('./cache/'),
Cameras: require('./cameras/'), Cameras: require('./cameras/'),
DOM: require('./dom/'),
EventEmitter: require('./events/EventEmitter'),
Game: require('./boot/Game'),
Math: require('./math'),
Geom: require('./geom'),
Display: require('./display'),
Input: require('./input'),
GameObjects: require('./gameobjects'),
Scene: require('./scene/local/Scene'),
Loader: {
ImageFile: require('./loader/filetypes/ImageFile')
},
Sound: require('./sound'),
Structs: require('./structs'),
Curves: require('./curves'),
Physics: require('./physics'),
Class: require('./utils/Class'), Class: require('./utils/Class'),
Create: require('./create/'),
Utils: require('./utils') Curves: require('./curves/'),
Display: require('./display/'),
DOM: require('./dom/'),
EventEmitter: require('./events/EventEmitter'),
Game: require('./boot/Game'),
GameObjects: require('./gameobjects/'),
Geom: require('./geom/'),
Input: require('./input/'),
Loader: require('./loader/'),
Math: require('./math/'),
Physics: require('./physics/'),
Scene: require('./scene/Scene'),
Sound: require('./sound/'),
Structs: require('./structs/'),
Textures: require('./textures/'),
Time: require('./time/'),
Tweens: require('./tweens/'),
Utils: require('./utils/')
}; };

View file

@ -1,20 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var World = require('./World');
var Arcade = new Class({
initialize:
function Arcade (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
}
});
module.exports = Arcade;

View file

@ -0,0 +1,100 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var Merge = require('../../utils/object/Merge');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Arcade.ArcadePhysics
var ArcadePhysics = new Class({
initialize:
function ArcadePhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'physics';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'arcade', {}),
GetFastValue(gameConfig, 'arcade', {})
);
return config;
},
boot: function ()
{
this.world = new World(this.scene, this.config);
this.add = new Factory(this.world);
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('postupdate', this.world.postUpdate, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
overlap: function (object1, object2, overlapCallback, processCallback, callbackContext)
{
if (overlapCallback === undefined) { overlapCallback = null; }
if (processCallback === undefined) { processCallback = null; }
if (callbackContext === undefined) { callbackContext = overlapCallback; }
return this.world.collideObjects(object1, object2, overlapCallback, processCallback, callbackContext, true);
},
collide: function (object1, object2, collideCallback, processCallback, callbackContext)
{
if (collideCallback === undefined) { collideCallback = null; }
if (processCallback === undefined) { processCallback = null; }
if (callbackContext === undefined) { callbackContext = collideCallback; }
return this.world.collideObjects(object1, object2, collideCallback, processCallback, callbackContext, false);
},
// Utils
accelerateTo: require('./utils/AccelerateTo'),
accelerateToObject: require('./utils/AccelerateToObject'),
closest: require('./utils/Closest'),
furthest: require('./utils/Furthest'),
moveTo: require('./utils/MoveTo'),
moveToObject: require('./utils/MoveToObject'),
velocityFromAngle: require('./utils/VelocityFromAngle'),
velocityFromRotation: require('./utils/VelocityFromRotation'),
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('arcadePhysics', ArcadePhysics);
module.exports = ArcadePhysics;

View file

@ -1,5 +1,3 @@
// Phaser.Physics.Arcade.World
var Body = require('./Body'); var Body = require('./Body');
var Class = require('../../utils/Class'); var Class = require('../../utils/Class');
var Collider = require('./Collider'); var Collider = require('./Collider');
@ -13,6 +11,8 @@ var Set = require('../../structs/Set');
var StaticBody = require('./StaticBody'); var StaticBody = require('./StaticBody');
var Vector2 = require('../../math/Vector2'); var Vector2 = require('../../math/Vector2');
// Phaser.Physics.Arcade.World
var World = new Class({ var World = new Class({
Extends: EventEmitter, Extends: EventEmitter,
@ -399,16 +399,6 @@ var World = new Class({
collideGroupVsTilemapLayer: require('./inc/CollideGroupVsTilemapLayer'), collideGroupVsTilemapLayer: require('./inc/CollideGroupVsTilemapLayer'),
collideSpriteVsTilemapLayer: require('./inc/CollideSpriteVsTilemapLayer'), collideSpriteVsTilemapLayer: require('./inc/CollideSpriteVsTilemapLayer'),
// Utils
accelerateTo: require('./utils/AccelerateTo'),
accelerateToObject: require('./utils/AccelerateToObject'),
closest: require('./utils/Closest'),
furthest: require('./utils/Furthest'),
moveTo: require('./utils/MoveTo'),
moveToObject: require('./utils/MoveToObject'),
velocityFromAngle: require('./utils/VelocityFromAngle'),
velocityFromRotation: require('./utils/VelocityFromRotation'),
// TODO // TODO
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly) collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly)
{ {

View file

@ -11,10 +11,30 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
return false; return false;
} }
var mapData = tilemapLayer.getTilesWithinWorldXY( var x = body.position.x;
body.position.x, body.position.y, var y = body.position.y;
body.width, body.height var w = body.width;
); var h = body.height;
// TODO: this logic should be encapsulated within the Tilemap API at some point.
// If the map's base tile size differs from the layer's tile size, we need to adjust the
// selection area by the difference between the two.
var layerData = tilemapLayer.layer;
if (layerData.tileWidth > layerData.baseTileWidth)
{
// The x origin of a tile is the left side, so x and width need to be adjusted.
let xDiff = (layerData.tileWidth - layerData.baseTileWidth) * tilemapLayer.scaleX;
x -= xDiff;
w += xDiff;
}
if (layerData.tileHeight > layerData.baseTileHeight)
{
// The y origin of a tile is the bottom side, so just the height needs to be adjusted.
let yDiff = (layerData.tileHeight - layerData.baseTileHeight) * tilemapLayer.scaleY;
h += yDiff;
}
var mapData = tilemapLayer.getTilesWithinWorldXY(x, y, w, h);
if (mapData.length === 0) if (mapData.length === 0)
{ {
@ -29,6 +49,14 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
tile = mapData[i]; tile = mapData[i];
tileWorldRect.left = tilemapLayer.tileToWorldX(tile.x); tileWorldRect.left = tilemapLayer.tileToWorldX(tile.x);
tileWorldRect.top = tilemapLayer.tileToWorldY(tile.y); tileWorldRect.top = tilemapLayer.tileToWorldY(tile.y);
// If the map's base tile size differs from the layer's tile size, only the top of the rect
// needs to be adjusted since it's origin is (0, 1).
if (tile.baseHeight !== tile.height)
{
tileWorldRect.top -= (tile.height - tile.baseHeight) * tilemapLayer.scaleY;
}
tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX; tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX;
tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY; tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY;

View file

@ -55,7 +55,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
{ {
if (faceHorizontal) if (faceHorizontal)
{ {
ox = TileCheckX(body, tile, tilemapLayer, tileBias); ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
// That's horizontal done, check if we still intersects? If not then we can return now // That's horizontal done, check if we still intersects? If not then we can return now
if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body)) if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -66,14 +66,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
if (faceVertical) if (faceVertical)
{ {
oy = TileCheckY(body, tile, tilemapLayer, tileBias); oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
} }
} }
else else
{ {
if (faceVertical) if (faceVertical)
{ {
oy = TileCheckY(body, tile, tilemapLayer, tileBias); oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
// That's vertical done, check if we still intersects? If not then we can return now // That's vertical done, check if we still intersects? If not then we can return now
if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body)) if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -84,7 +84,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
if (faceHorizontal) if (faceHorizontal)
{ {
ox = TileCheckX(body, tile, tilemapLayer, tileBias); ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
} }
} }

View file

@ -10,12 +10,9 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred. * @return {number} The amount of separation that occurred.
*/ */
var TileCheckX = function (body, tile, tilemapLayer, tileBias) var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias)
{ {
var ox = 0; var ox = 0;
var tileLeft = tilemapLayer.tileToWorldX(tile.x);
var tileWidth = tile.width * tilemapLayer.scaleX;
var tileRight = tileLeft + tileWidth;
if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left) if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left)
{ {

View file

@ -10,12 +10,9 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred. * @return {number} The amount of separation that occurred.
*/ */
var TileCheckY = function (body, tile, tilemapLayer, tileBias) var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias)
{ {
var oy = 0; var oy = 0;
var tileTop = tilemapLayer.tileToWorldX(tile.y);
var tileHeight = tile.height * tilemapLayer.scaleY;
var tileBottom = tileTop + tileHeight;
if (body.deltaY() < 0 && !body.blocked.up && tile.collideDown && body.checkCollision.up) if (body.deltaY() < 0 && !body.blocked.up && tile.collideDown && body.checkCollision.up)
{ {

View file

@ -1,15 +1,16 @@
// Phaser.Physics.Arcade // Phaser.Physics.Arcade
// World updated to run off the Phaser main loop.
// Body extended to support additional setter functions.
module.exports = { module.exports = {
ArcadePhysics: require('./ArcadePhysics'),
Body: require('./Body'), Body: require('./Body'),
Collider: require('./Collider'),
Factory: require('./Factory'), Factory: require('./Factory'),
Group: require('./PhysicsGroup'), Group: require('./PhysicsGroup'),
Image: require('./ArcadeImage'), Image: require('./ArcadeImage'),
Sprite: require('./ArcadeSprite'), Sprite: require('./ArcadeSprite'),
StaticBody: require('./StaticBody'),
StaticGroup: require('./StaticPhysicsGroup'),
World: require('./World') World: require('./World')
}; };

View file

@ -1,20 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var World = require('./World');
var Impact = new Class({
initialize:
function Impact (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
}
});
module.exports = Impact;

View file

@ -0,0 +1,71 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var Merge = require('../../utils/object/Merge');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Impact.ImpactPhysics
var ImpactPhysics = new Class({
initialize:
function ImpactPhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'impact';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'impact', {}),
GetFastValue(gameConfig, 'impact', {})
);
return config;
},
boot: function ()
{
this.world = new World(this.scene, this.config);
this.add = new Factory(this.world);
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('impactPhysics', ImpactPhysics);
module.exports = ImpactPhysics;

View file

@ -216,11 +216,6 @@ var World = new Class({
return this; return this;
}, },
postUpdate: function ()
{
// NOOP
},
update: function (time, delta) update: function (time, delta)
{ {
if (!this.enabled || this.bodies.size === 0) if (!this.enabled || this.bodies.size === 0)

View file

@ -15,10 +15,14 @@
module.exports = { module.exports = {
Body: require('./Body'), Body: require('./Body'),
Body: require('./ImpactBody'),
COLLIDES: require('./COLLIDES'), COLLIDES: require('./COLLIDES'),
CollisionMap: require('./CollisionMap'), CollisionMap: require('./CollisionMap'),
Factory: require('./Factory'),
Image: require('./ImpactImage'),
ImpactPhysics: require('./ImpactPhysics'),
Sprite: require('./ImpactSprite'),
TYPE: require('./TYPE'), TYPE: require('./TYPE'),
World: require('./World'), World: require('./World')
Factory: require('./Factory')
}; };

View file

@ -1,8 +1,10 @@
// Phaser.Physics // Phaser.Physics
module.exports = { module.exports = {
Arcade: require('./arcade'), Arcade: require('./arcade'),
Impact: require('./impact'), Impact: require('./impact'),
Matter: require('./matter-js/CustomMain'), Matter: require('./matter-js'),
PolyDecomp: require('./poly-decomp') PolyDecomp: require('./poly-decomp')
}; };

View file

@ -1,57 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetValue = require('../../utils/object/GetValue');
var MatterAttractors = require('./lib/plugins/MatterAttractors');
var MatterLib = require('./lib/core/Matter');
var MatterWrap = require('./lib/plugins/MatterWrap');
var Plugin = require('./lib/core/Plugin');
var World = require('./World');
var Matter = new Class({
initialize:
// Referenced from the Scene PhysicsManager as `system`
function Matter (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
// Matter plugins
if (GetValue(config, 'plugins.attractors', false))
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
}
if (GetValue(config, 'plugins.wrap', false))
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
}
},
enableAttractorPlugin: function ()
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
return this;
},
enableWrapPlugin: function ()
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
return this;
}
});
module.exports = Matter;

View file

@ -0,0 +1,111 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var GetValue = require('../../utils/object/GetValue');
var MatterAttractors = require('./lib/plugins/MatterAttractors');
var MatterLib = require('./lib/core/Matter');
var MatterWrap = require('./lib/plugins/MatterWrap');
var Merge = require('../../utils/object/Merge');
var Plugin = require('./lib/core/Plugin');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Matter.MatterPhysics
var MatterPhysics = new Class({
initialize:
// Referenced from the Scene PhysicsManager as `system`
function MatterPhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'matter';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'matter', {}),
GetFastValue(gameConfig, 'matter', {})
);
return config;
},
boot: function ()
{
var config = this.config;
this.world = new World(this.scene, config);
this.add = new Factory(this.world);
// Matter plugins
if (GetValue(config, 'plugins.attractors', false))
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
}
if (GetValue(config, 'plugins.wrap', false))
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
}
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('postupdate', this.world.postUpdate, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
enableAttractorPlugin: function ()
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
return this;
},
enableWrapPlugin: function ()
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
return this;
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('matterPhysics', MatterPhysics);
module.exports = MatterPhysics;

View file

@ -307,36 +307,38 @@ var World = new Class({
postUpdate: function () postUpdate: function ()
{ {
if (this.drawDebug) if (!this.drawDebug)
{ {
var graphics = this.debugGraphic; return;
var bodies = Composite.allBodies(this.localWorld); }
graphics.clear(); var graphics = this.debugGraphic;
graphics.lineStyle(1, this.defaults.bodyDebugColor); var bodies = Composite.allBodies(this.localWorld);
for (var i = 0; i < bodies.length; i++) graphics.clear();
graphics.lineStyle(1, this.defaults.bodyDebugColor);
for (var i = 0; i < bodies.length; i++)
{
var body = bodies[i];
if (!body.render.visible)
{ {
var body = bodies[i]; continue;
if (!body.render.visible)
{
continue;
}
var vertices = body.vertices;
graphics.moveTo(vertices[0].x, vertices[0].y);
for (var j = 1; j < vertices.length; j++)
{
graphics.lineTo(vertices[j].x, vertices[j].y);
}
graphics.lineTo(vertices[0].x, vertices[0].y);
graphics.strokePath();
} }
var vertices = body.vertices;
graphics.moveTo(vertices[0].x, vertices[0].y);
for (var j = 1; j < vertices.length; j++)
{
graphics.lineTo(vertices[j].x, vertices[j].y);
}
graphics.lineTo(vertices[0].x, vertices[0].y);
graphics.strokePath();
} }
}, },
@ -362,7 +364,6 @@ var World = new Class({
destroy: function () destroy: function ()
{ {
// TODO
this.shutdown(); this.shutdown();
} }

View file

@ -0,0 +1,12 @@
// Phaser.Physics.Matter
module.exports = {
Factory: require('./Factory'),
Image: require('./MatterImage'),
Matter: require('./CustomMain'),
MatterPhysics: require('./MatterPhysics'),
Sprite: require('./MatterSprite'),
World: require('./World')
};

View file

@ -16,20 +16,29 @@ var PluginManager = new Class({
{ {
}, },
install: function (scene, config) install: function (scene, globalPlugins, localPlugins)
{ {
var i;
var pluginKey;
var sys = scene.sys; var sys = scene.sys;
for (var i = 0; i < config.length; i++) for (var i = 0; i < globalPlugins.length; i++)
{ {
var p = config[i]; pluginKey = globalPlugins[i];
console.log('installing', p); sys.scene[pluginKey] = sys[pluginKey];
}
if (plugins[p]) for (var i = 0; i < localPlugins.length; i++)
{
pluginKey = localPlugins[i];
if (plugins[pluginKey])
{ {
// console.log('installing', pluginKey);
// Install a local reference inside of Systems // Install a local reference inside of Systems
sys[p] = new plugins[p](scene); sys[pluginKey] = new plugins[pluginKey](scene);
} }
} }
}, },
@ -52,7 +61,7 @@ PluginManager.register = function (key, plugin)
{ {
plugins[key] = plugin; plugins[key] = plugin;
console.log('PluginManager.register', key); // console.log('PluginManager.register', key);
}; };
module.exports = PluginManager; module.exports = PluginManager;

View file

@ -1,5 +1,5 @@
// These properties get injected into the Scene and map to local systems // These properties get injected into the Scene and map to local systems
// The map key is the local system reference, the value is the property that is added to the Scene // The map key is the property that is added to the Scene, the value is the Scene.Systems reference
// These defaults can be modified via the Scene config object // These defaults can be modified via the Scene config object
var InjectionMap = { var InjectionMap = {
@ -14,14 +14,16 @@ var InjectionMap = {
add: 'add', add: 'add',
cameras: 'cameras', cameras: 'cameras',
children: 'displayList',
data: 'data', data: 'data',
displayList: 'children',
events: 'events', events: 'events',
inputManager: 'input', impact: 'impactPhysics',
input: 'input',
load: 'load', load: 'load',
make: 'make', make: 'make',
physicsManager: 'physics', matter: 'matterPhysics',
sceneManager: 'scene', physics: 'arcadePhysics',
scene: 'sceneManager',
time: 'time', time: 'time',
tweens: 'tweens' tweens: 'tweens'

View file

@ -1,5 +1,4 @@
var Class = require('../utils/Class');
var Class = require('../../utils/Class');
var Systems = require('./Systems'); var Systems = require('./Systems');
var Scene = new Class({ var Scene = new Class({

View file

@ -4,8 +4,8 @@ var Class = require('../utils/Class');
var CONST = require('../const'); var CONST = require('../const');
var GetValue = require('../utils/object/GetValue'); var GetValue = require('../utils/object/GetValue');
var NOOP = require('../utils/NOOP'); var NOOP = require('../utils/NOOP');
var Scene = require('./local/Scene'); var Scene = require('./Scene');
var Systems = require('./local/Systems'); var Systems = require('./Systems');
var SceneManager = new Class({ var SceneManager = new Class({

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var PluginManager = require('../../plugins/PluginManager'); var PluginManager = require('../plugins/PluginManager');
// A proxy class to the Global Scene Manager // A proxy class to the Global Scene Manager
var SceneManager = new Class({ var SceneManager = new Class({
@ -32,11 +32,12 @@ var SceneManager = new Class({
{ {
this.systems.inject(this); this.systems.inject(this);
this.systems.events.on('preupdate', this.preUpdate, this);
this.systems.events.on('shutdown', this.shutdown, this); this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this); this.systems.events.on('destroy', this.destroy, this);
}, },
update: function () preUpdate: function ()
{ {
var len = this._queue.length; var len = this._queue.length;

View file

@ -1,6 +1,6 @@
var CONST = require('../const'); var CONST = require('./const');
var ScaleModes = require('../../renderer/ScaleModes'); var ScaleModes = require('../renderer/ScaleModes');
var GetValue = require('../../utils/object/GetValue'); var GetValue = require('../utils/object/GetValue');
var InjectionMap = require('./InjectionMap'); var InjectionMap = require('./InjectionMap');
var Settings = { var Settings = {

View file

@ -1,21 +1,8 @@
// var CameraManager = require('../../camera/local/CameraManager'); var Class = require('../utils/Class');
var Class = require('../../utils/Class');
var Clock = require('../../time/Clock');
var Data = require('../../data/Data');
var DataStore = require('../../data/DataStore');
var DisplayList = require('../plugins/DisplayList');
var EventEmitter = require('eventemitter3'); var EventEmitter = require('eventemitter3');
var GameObjectCreator = require('../plugins/GameObjectCreator'); var GetFastValue = require('../utils/object/GetFastValue');
var GameObjectFactory = require('../plugins/GameObjectFactory'); var ScenePlugin = require('./ScenePlugin');
var InputManager = require('../../input/InputPlugin');
var Loader = require('../plugins/Loader');
var PhysicsManager = require('../plugins/PhysicsManager');
var SceneManager = require('../plugins/SceneManager');
var Settings = require('./Settings'); var Settings = require('./Settings');
var TweenManager = require('../../tweens/manager/TweenManager');
var UpdateList = require('../plugins/UpdateList');
var TestPlugin = require('../../plugins/TestPlugin');
var Systems = new Class({ var Systems = new Class({
@ -31,7 +18,7 @@ var Systems = new Class({
this.settings = Settings.create(config); this.settings = Settings.create(config);
// Set by the GlobalSceneManager - a reference to the Scene canvas / context // Set by the SceneManager - a reference to the Scene canvas / context
this.canvas; this.canvas;
this.context; this.context;
@ -74,27 +61,55 @@ var Systems = new Class({
this.events = new EventEmitter(); this.events = new EventEmitter();
game.plugins.install(scene, [ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make' ]); game.plugins.install(scene,
[ 'anims', 'cache', 'registry', 'sound', 'textures' ],
[ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make', 'load', 'tweens', 'input' ]
);
// Optional Scene plugins - not referenced by core systems, can be overridden with user code var physics = this.getPhysicsSystem();
// game.plugins.install(scene, [ , 'test' ]); if (physics)
{
this.data = new Data(scene); game.plugins.install(scene, [], physics);
this.dataStore = new DataStore(scene); }
this.inputManager = new InputManager(scene);
this.load = new Loader(scene);
this.physicsManager = new PhysicsManager(scene);
this.tweens = new TweenManager(scene);
// Sometimes the managers need access to a system created after them
this.events.emit('boot', this); this.events.emit('boot', this);
},
this.inputManager.boot(); getPhysicsSystem: function ()
this.physicsManager.boot(); {
var defaultSystem = this.game.config.defaultPhysicsSystem;
var sceneSystems = GetFastValue(this.settings, 'physics', false);
this.inject2(); if (!defaultSystem && !sceneSystems)
{
// No default physics system or systems in this scene
return;
}
// Let's build the systems array
var output = [];
if (defaultSystem)
{
output.push(defaultSystem + 'Physics');
}
if (sceneSystems)
{
for (var key in sceneSystems)
{
key = key.concat('Physics');
if (output.indexOf(key) === -1)
{
output.push(key);
}
}
}
// An array of Physics systems to start for this Scene
return output;
}, },
inject: function (plugin) inject: function (plugin)
@ -107,49 +122,20 @@ var Systems = new Class({
} }
}, },
inject2: function ()
{
var map = this.settings.map;
for (var key in map)
{
if (key === 'sys')
{
continue;
}
this.scene[map[key]] = this[key];
}
},
step: function (time, delta) step: function (time, delta)
{ {
// Are there any pending SceneManager actions? this.events.emit('preupdate', time, delta);
// This plugin is a special case, as it can literally modify this Scene, so we update it directly.
this.sceneManager.update();
if (!this.settings.active) if (!this.settings.active)
{ {
return; return;
} }
this.events.emit('preupdate', time, delta);
this.tweens.begin(time);
this.inputManager.begin(time);
this.events.emit('update', time, delta); this.events.emit('update', time, delta);
this.physicsManager.update(time, delta);
this.tweens.update(time, delta);
this.inputManager.update(time, delta);
this.scene.update.call(this.scene, time, delta); this.scene.update.call(this.scene, time, delta);
this.events.emit('postupdate', time, delta); this.events.emit('postupdate', time, delta);
this.physicsManager.postUpdate();
}, },
render: function (interpolation, renderer) render: function (interpolation, renderer)
@ -181,100 +167,67 @@ var Systems = new Class({
// A paused Scene 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 GlobalSceneManager // Was paused by the SceneManager
this.settings.active = false; this.settings.active = false;
if (this.scene.pause) this.events.emit('pause', this);
{
this.scene.pause.call(this.scene);
}
}, },
resume: function () resume: function ()
{ {
// Was resumed by the GlobalSceneManager // Was resumed by the SceneManager
this.settings.active = true; this.settings.active = true;
if (this.scene.resume) this.events.emit('resume', this);
{
this.scene.resume.call(this.scene);
}
}, },
sleep: function () sleep: function ()
{ {
// Was sent to sleep by the GlobalSceneManager // Was sent to sleep by the SceneManager
this.settings.active = false; this.settings.active = false;
this.settings.visible = false; this.settings.visible = false;
if (this.scene.sleep) this.events.emit('sleep', this);
{
this.scene.sleep.call(this.scene);
}
}, },
wake: function () wake: function ()
{ {
// Was woken up by the GlobalSceneManager // Was woken up by the SceneManager
this.settings.active = true; this.settings.active = true;
this.settings.visible = true; this.settings.visible = true;
if (this.scene.wake) this.events.emit('wake', this);
{
this.scene.wake.call(this.scene);
}
}, },
start: function (data) start: function (data)
{ {
// Was started by the GlobalSceneManager // Was started by the SceneManager
this.settings.data = data; this.settings.data = data;
this.settings.active = true; this.settings.active = true;
this.settings.visible = true; this.settings.visible = true;
this.events.emit('start', this);
}, },
shutdown: function () shutdown: function ()
{ {
// Was stopped by the GlobalSceneManager // Was stopped by the SceneManager
this.settings.active = false; this.settings.active = false;
this.settings.visible = false; this.settings.visible = false;
this.events.emit('shutdown', this); this.events.emit('shutdown', this);
// this.displayList.shutdown();
// this.updateList.shutdown();
// this.time.shutdown();
this.tweens.shutdown();
this.physicsManager.shutdown();
if (this.scene.shutdown)
{
this.scene.shutdown.call(this.scene);
}
}, },
// TODO: Game level nuke
destroy: function () destroy: function ()
{ {
this.events.emit('destroy', this); this.events.emit('destroy', this);
this.add.destroy();
// this.time.destroy();
this.tweens.destroy();
this.physicsManager.destroy();
// etc
if (this.scene.destroy)
{
this.scene.destroy.call(this.scene);
}
} }
}); });

View file

@ -1,92 +0,0 @@
var Class = require('../../utils/Class');
var GetValue = require('../../utils/object/GetValue');
var Merge = require('../../utils/object/Merge');
var NOOP = require('../../utils/NOOP');
// Physics Systems (TODO: Remove from here)
var Arcade = require('../../physics/arcade/Arcade');
var Impact = require('../../physics/impact/Impact');
var Matter = require('../../physics/matter-js/Matter');
var PhysicsManager = new Class({
initialize:
function PhysicsManager (scene)
{
this.scene = scene;
this.gameConfig = scene.sys.game.config.physics;
this.defaultSystem = scene.sys.game.config.defaultPhysicsSystem;
this.sceneConfig = scene.sys.settings.physics;
// This gets set to an instance of the physics system during boot
this.system;
// This gets set by the physics system during boot
this.world = { update: NOOP, postUpdate: NOOP, shutdown: NOOP, destroy: NOOP };
// This gets set by the physics system during boot
this.add;
},
boot: function ()
{
var sceneSystem = GetValue(this.sceneConfig, 'system', false);
if (!this.defaultSystem && !sceneSystem)
{
// No default physics system or system in this scene, so abort
return;
}
// Which physics system are we using in this Scene?
var system = (sceneSystem !== false) ? sceneSystem : this.defaultSystem;
// Create the config for it
var config = Merge(this.sceneConfig, GetValue(this.gameConfig, system, {}));
switch (system)
{
case 'arcade':
this.system = new Arcade(this, config);
break;
case 'impact':
this.system = new Impact(this, config);
break;
case 'matter':
this.system = new Matter(this, config);
break;
}
},
remove: function (object)
{
this.world.remove(object);
},
update: function (time, delta)
{
this.world.update(time, delta);
},
postUpdate: function ()
{
this.world.postUpdate();
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
module.exports = PhysicsManager;

11
src/textures/index.js Normal file
View file

@ -0,0 +1,11 @@
// Phaser.Textures
module.exports = {
FilterMode: require('./FilterMode'),
Frame: require('./Frame'),
Texture: require('./Texture'),
TextureManager: require('./TextureManager'),
TextureSource: require('./TextureSource')
};

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var TweenBuilder = require('../builder/TweenBuilder'); var TweenBuilder = require('./builder/TweenBuilder');
var TWEEN_CONST = require('../tween/const'); var TWEEN_CONST = require('./tween/const');
// Phaser.Tweens.Timeline // Phaser.Tweens.Timeline

View file

@ -1,8 +1,9 @@
var Class = require('../../utils/Class'); var Class = require('../utils/Class');
var TimelineBuilder = require('../builder/TimelineBuilder'); var NumberTweenBuilder = require('./builder/NumberTweenBuilder');
var TweenBuilder = require('../builder/TweenBuilder'); var PluginManager = require('../plugins/PluginManager');
var NumberTweenBuilder = require('../builder/NumberTweenBuilder'); var TimelineBuilder = require('./builder/TimelineBuilder');
var TWEEN_CONST = require('../tween/const'); var TWEEN_CONST = require('./tween/const');
var TweenBuilder = require('./builder/TweenBuilder');
// Phaser.Tweens.TweenManager // Phaser.Tweens.TweenManager
@ -12,9 +13,15 @@ var TweenManager = new Class({
function TweenManager (scene) function TweenManager (scene)
{ {
// The Scene the Tween Manager belongs to (tweens are Scene specific, not Game global) // The Scene that owns this plugin
this.scene = scene; this.scene = scene;
this.systems = scene.sys;
this.mapping = 'tweens';
this.systems.events.on('boot', this.boot, this);
this.timeScale = 1; this.timeScale = 1;
this._add = []; this._add = [];
@ -25,9 +32,15 @@ var TweenManager = new Class({
this._toProcess = 0; this._toProcess = 0;
}, },
// Scene is starting up
boot: function () boot: function ()
{ {
this.systems.inject(this);
this.systems.events.on('preupdate', this.preUpdate, this);
this.systems.events.on('update', this.update, this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
this.timeScale = 1; this.timeScale = 1;
}, },
@ -92,7 +105,7 @@ var TweenManager = new Class({
return tween; return tween;
}, },
begin: function () preUpdate: function ()
{ {
if (this._toProcess === 0) if (this._toProcess === 0)
{ {
@ -466,4 +479,6 @@ var TweenManager = new Class({
}); });
PluginManager.register('tweens', TweenManager);
module.exports = TweenManager; module.exports = TweenManager;

View file

@ -7,7 +7,7 @@ var GetTargets = require('./GetTargets');
var GetTweens = require('./GetTweens'); var GetTweens = require('./GetTweens');
var GetValue = require('../../utils/object/GetValue'); var GetValue = require('../../utils/object/GetValue');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Timeline = require('../timeline/Timeline'); var Timeline = require('../Timeline');
var TweenBuilder = require('./TweenBuilder'); var TweenBuilder = require('./TweenBuilder');
// Phaser.Tweens.TimelineBuilder // Phaser.Tweens.TimelineBuilder

View file

@ -2,9 +2,9 @@
module.exports = { module.exports = {
TweenManager: require('./manager/TweenManager'), TweenManager: require('./TweenManager'),
Tween: require('./tween/Tween'), Tween: require('./tween/Tween'),
TweenData: require('./tween/TweenData'), TweenData: require('./tween/TweenData'),
Timeline: require('./timeline/Timeline') Timeline: require('./Timeline')
}; };

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class'); var Class = require('../../utils/Class');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); var GameObjectCreator = require('../../gameobjects/GameObjectCreator');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var GameObjectFactory = require('../../gameobjects/GameObjectFactory');
var TWEEN_CONST = require('./const'); var TWEEN_CONST = require('./const');
// Phaser.Tweens.Tween // Phaser.Tweens.Tween