diff --git a/src/animations/index.js b/src/animations/index.js new file mode 100644 index 000000000..228eea4fe --- /dev/null +++ b/src/animations/index.js @@ -0,0 +1,9 @@ +// Phaser.Animations + +module.exports = { + + Animation: require('./Animation'), + AnimationFrame: require('./AnimationFrame'), + AnimationManager: require('./AnimationManager'), + +}; diff --git a/src/cache/index.js b/src/cache/index.js new file mode 100644 index 000000000..cf7e6c02f --- /dev/null +++ b/src/cache/index.js @@ -0,0 +1,8 @@ +// Phaser.Cache + +module.exports = { + + BaseCache: require('./BaseCache'), + CacheManager: require('./CacheManager') + +}; diff --git a/src/cameras/2d/CameraManager.js b/src/cameras/2d/CameraManager.js index 4fd7e78df..0c8f15826 100644 --- a/src/cameras/2d/CameraManager.js +++ b/src/cameras/2d/CameraManager.js @@ -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: [ @@ -246,7 +227,7 @@ var CameraManager = new Class({ } }, - removeCamera: function (camera) + remove: function (camera) { var cameraIndex = this.cameras.indexOf(camera); @@ -298,6 +279,25 @@ var CameraManager = new Class({ 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; } }); diff --git a/src/curves/path/Path.js b/src/curves/path/Path.js index 2c0be7846..0e282a694 100644 --- a/src/curves/path/Path.js +++ b/src/curves/path/Path.js @@ -3,7 +3,7 @@ var Class = require('../../utils/Class'); var CubicBezierCurve = require('../cubicbezier/CubicBezierCurve'); var EllipseCurve = require('../ellipse/EllipseCurve'); -var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); +var GameObjectFactory = require('../../gameobjects/GameObjectFactory'); var LineCurve = require('../line/LineCurve'); var MovePathTo = require('./MoveTo'); var Rectangle = require('../../geom/rectangle/Rectangle'); diff --git a/src/scene/plugins/DisplayList.js b/src/gameobjects/DisplayList.js similarity index 98% rename from src/scene/plugins/DisplayList.js rename to src/gameobjects/DisplayList.js index 7454e01f9..a3d8e7e75 100644 --- a/src/scene/plugins/DisplayList.js +++ b/src/gameobjects/DisplayList.js @@ -1,6 +1,6 @@ -var Class = require('../../utils/Class'); -var StableSort = require('../../utils/array/StableSort'); -var PluginManager = require('../../plugins/PluginManager'); +var Class = require('../utils/Class'); +var StableSort = require('../utils/array/StableSort'); +var PluginManager = require('../plugins/PluginManager'); var DisplayList = new Class({ @@ -13,7 +13,7 @@ var DisplayList = new Class({ this.systems = scene.sys; - this.mapping = 'add'; + this.mapping = 'children'; this.systems.events.on('boot', this.boot, this); diff --git a/src/gameobjects/GameObject.js b/src/gameobjects/GameObject.js index d31fe7127..431e6ce0a 100644 --- a/src/gameobjects/GameObject.js +++ b/src/gameobjects/GameObject.js @@ -226,7 +226,7 @@ var GameObject = new Class({ */ setInteractive: function (shape, callback) { - this.scene.sys.inputManager.enable(this, shape, callback); + this.scene.sys.input.enable(this, shape, callback); return this; }, @@ -282,25 +282,27 @@ var GameObject = new Class({ this.preDestroy.call(this); } - this.scene.sys.displayList.remove(this); - this.scene.sys.updateList.remove(this); + var sys = this.scene.sys; + + sys.displayList.remove(this); + sys.updateList.remove(this); if (this.input) { - this.scene.sys.inputManager.clear(this); + sys.input.clear(this); this.input = undefined; } // TODO Keep a reference to the manager in Body, so body can remove itself, not via System if (this.body) { - this.scene.sys.physicsManager.remove(this); + sys.physicsManager.remove(this); this.body = undefined; } // Tell the Scene to re-sort the children - this.scene.sys.queueDepthSort(); + sys.queueDepthSort(); this.active = false; this.visible = false; diff --git a/src/scene/plugins/GameObjectCreator.js b/src/gameobjects/GameObjectCreator.js similarity index 92% rename from src/scene/plugins/GameObjectCreator.js rename to src/gameobjects/GameObjectCreator.js index 7d91a9cdf..d90eb259c 100644 --- a/src/scene/plugins/GameObjectCreator.js +++ b/src/gameobjects/GameObjectCreator.js @@ -1,5 +1,5 @@ -var Class = require('../../utils/Class'); -var PluginManager = require('../../plugins/PluginManager'); +var Class = require('../utils/Class'); +var PluginManager = require('../plugins/PluginManager'); var GameObjectCreator = new Class({ diff --git a/src/scene/plugins/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js similarity index 91% rename from src/scene/plugins/GameObjectFactory.js rename to src/gameobjects/GameObjectFactory.js index 5cf473fbe..c64d08464 100644 --- a/src/scene/plugins/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -1,5 +1,5 @@ -var Class = require('../../utils/Class'); -var PluginManager = require('../../plugins/PluginManager'); +var Class = require('../utils/Class'); +var PluginManager = require('../plugins/PluginManager'); var GameObjectFactory = new Class({ @@ -12,7 +12,7 @@ var GameObjectFactory = new Class({ this.systems = scene.sys; - this.mapping = 'time'; + this.mapping = 'add'; this.systems.events.on('boot', this.boot, this); diff --git a/src/scene/plugins/UpdateList.js b/src/gameobjects/UpdateList.js similarity index 94% rename from src/scene/plugins/UpdateList.js rename to src/gameobjects/UpdateList.js index c8ba8d470..9a2a7f302 100644 --- a/src/scene/plugins/UpdateList.js +++ b/src/gameobjects/UpdateList.js @@ -1,7 +1,6 @@ -var Class = require('../../utils/Class'); -var PluginManager = require('../../plugins/PluginManager'); +var Class = require('../utils/Class'); +var PluginManager = require('../plugins/PluginManager'); -// TODO - Extend from ProcessQueue var UpdateList = new Class({ initialize: @@ -12,7 +11,7 @@ var UpdateList = new Class({ this.systems = scene.sys; - this.mapping = 'children'; + this.mapping = null; this.systems.events.on('boot', this.boot, this); diff --git a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js index 3bbc4758f..fdd98c551 100644 --- a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js +++ b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js @@ -1,6 +1,6 @@ var BitmapText = require('./DynamicBitmapText'); var BuildGameObject = require('../../BuildGameObject'); -var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../../GameObjectCreator'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); // When registering a factory function 'this' refers to the GameObjectCreator context. diff --git a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js index 390e909c3..5e41af81c 100644 --- a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js +++ b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/bitmaptext/static/BitmapTextCreator.js b/src/gameobjects/bitmaptext/static/BitmapTextCreator.js index 46d8260c3..f4c07325f 100644 --- a/src/gameobjects/bitmaptext/static/BitmapTextCreator.js +++ b/src/gameobjects/bitmaptext/static/BitmapTextCreator.js @@ -1,6 +1,6 @@ var BitmapText = require('./BitmapText'); var BuildGameObject = require('../../BuildGameObject'); -var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../../GameObjectCreator'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetValue = require('../../../utils/object/GetValue'); diff --git a/src/gameobjects/bitmaptext/static/BitmapTextFactory.js b/src/gameobjects/bitmaptext/static/BitmapTextFactory.js index 62a52d7e0..83ec7e750 100644 --- a/src/gameobjects/bitmaptext/static/BitmapTextFactory.js +++ b/src/gameobjects/bitmaptext/static/BitmapTextFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/blitter/Blitter.js b/src/gameobjects/blitter/Blitter.js index 1eb2036c2..596c99ad4 100644 --- a/src/gameobjects/blitter/Blitter.js +++ b/src/gameobjects/blitter/Blitter.js @@ -2,7 +2,7 @@ var BlitterRender = require('./BlitterRender'); var Bob = require('./Bob'); var Class = require('../../utils/Class'); var Components = require('../components'); -var DisplayList = require('../../scene/plugins/DisplayList'); +var DisplayList = require('../DisplayList'); var GameObject = require('../GameObject'); /** diff --git a/src/gameobjects/blitter/BlitterCreator.js b/src/gameobjects/blitter/BlitterCreator.js index 13d757e8c..c05d0054b 100644 --- a/src/gameobjects/blitter/BlitterCreator.js +++ b/src/gameobjects/blitter/BlitterCreator.js @@ -1,6 +1,6 @@ var Blitter = require('./Blitter'); var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); // When registering a factory function 'this' refers to the GameObjectCreator context. diff --git a/src/gameobjects/blitter/BlitterFactory.js b/src/gameobjects/blitter/BlitterFactory.js index 988db0ef0..996efb27d 100644 --- a/src/gameobjects/blitter/BlitterFactory.js +++ b/src/gameobjects/blitter/BlitterFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/container/Container.js b/src/gameobjects/container/Container.js index 71da0e997..702881918 100644 --- a/src/gameobjects/container/Container.js +++ b/src/gameobjects/container/Container.js @@ -1,13 +1,10 @@ var Class = require('../../utils/Class'); var Components = require('../components'); var DataProxy = require('../components/DataProxy'); -var DisplayList = require('../../scene/plugins/DisplayList'); var TransformMatrix = require('../components/TransformMatrix'); var Container = new Class({ - // Extends: DisplayList, - // Mixins: [ // Components.Visible, // SpriteRender @@ -17,9 +14,6 @@ var Container = new Class({ function Container (scene, x, y) { - // this.list = children - // DisplayList.call(this, scene); - this.scene = scene; this.type = 'Container'; diff --git a/src/gameobjects/container/ContainerCreator.js b/src/gameobjects/container/ContainerCreator.js index f8397482d..6f259e139 100644 --- a/src/gameobjects/container/ContainerCreator.js +++ b/src/gameobjects/container/ContainerCreator.js @@ -1,5 +1,5 @@ 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. diff --git a/src/gameobjects/container/ContainerFactory.js b/src/gameobjects/container/ContainerFactory.js index 9e631680a..f552f6849 100644 --- a/src/gameobjects/container/ContainerFactory.js +++ b/src/gameobjects/container/ContainerFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/graphics/Graphics.js b/src/gameobjects/graphics/Graphics.js index 9953e9b2f..df190b8c4 100644 --- a/src/gameobjects/graphics/Graphics.js +++ b/src/gameobjects/graphics/Graphics.js @@ -261,6 +261,16 @@ var Graphics = new Class({ fillPoint: function (x, y, size) { + if (!size || size < 1) + { + size = 1; + } + else + { + x -= (size / 2); + y -= (size / 2); + } + this.commandBuffer.push( Commands.FILL_RECT, x, y, size, size @@ -429,6 +439,26 @@ var Graphics = new Class({ 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 diff --git a/src/gameobjects/graphics/GraphicsCreator.js b/src/gameobjects/graphics/GraphicsCreator.js index 7f36deca7..3600681f1 100644 --- a/src/gameobjects/graphics/GraphicsCreator.js +++ b/src/gameobjects/graphics/GraphicsCreator.js @@ -1,4 +1,4 @@ -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var Graphics = require('./Graphics'); // When registering a factory function 'this' refers to the GameObjectCreator context. diff --git a/src/gameobjects/graphics/GraphicsFactory.js b/src/gameobjects/graphics/GraphicsFactory.js index 528c02e0f..952ca6069 100644 --- a/src/gameobjects/graphics/GraphicsFactory.js +++ b/src/gameobjects/graphics/GraphicsFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/group/GroupCreator.js b/src/gameobjects/group/GroupCreator.js index f9aeb09b8..9c2d0a428 100644 --- a/src/gameobjects/group/GroupCreator.js +++ b/src/gameobjects/group/GroupCreator.js @@ -1,4 +1,4 @@ -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var Group = require('./Group'); // When registering a factory function 'this' refers to the GameObjectCreator context. diff --git a/src/gameobjects/group/GroupFactory.js b/src/gameobjects/group/GroupFactory.js index 22fcca0a1..08c4e7074 100644 --- a/src/gameobjects/group/GroupFactory.js +++ b/src/gameobjects/group/GroupFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/image/ImageCreator.js b/src/gameobjects/image/ImageCreator.js index 83e14b53f..f9dcf19cb 100644 --- a/src/gameobjects/image/ImageCreator.js +++ b/src/gameobjects/image/ImageCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Image = require('./Image'); diff --git a/src/gameobjects/image/ImageFactory.js b/src/gameobjects/image/ImageFactory.js index 3c4cb7888..bbe41c68b 100644 --- a/src/gameobjects/image/ImageFactory.js +++ b/src/gameobjects/image/ImageFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/index.js b/src/gameobjects/index.js index 9505a455c..d8b466422 100644 --- a/src/gameobjects/index.js +++ b/src/gameobjects/index.js @@ -2,6 +2,11 @@ var GameObjects = { + DisplayList: require('./DisplayList'), + UpdateList: require('./UpdateList'), + GameObjectCreator: require('./GameObjectCreator'), + GameObjectFactory: require('./GameObjectFactory'), + Components: require('./components'), BitmapText: require('./bitmaptext/static/BitmapText'), diff --git a/src/gameobjects/lightlayer/LightLayerCreator.js b/src/gameobjects/lightlayer/LightLayerCreator.js index 806ae2633..3b5b1c578 100644 --- a/src/gameobjects/lightlayer/LightLayerCreator.js +++ b/src/gameobjects/lightlayer/LightLayerCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var LightLayer = require('./LightLayer'); diff --git a/src/gameobjects/lightlayer/LightLayerFactory.js b/src/gameobjects/lightlayer/LightLayerFactory.js index 2c8375c7e..d81defab9 100644 --- a/src/gameobjects/lightlayer/LightLayerFactory.js +++ b/src/gameobjects/lightlayer/LightLayerFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/mesh/MeshCreator.js b/src/gameobjects/mesh/MeshCreator.js index 565aca0fb..7fdff5df3 100644 --- a/src/gameobjects/mesh/MeshCreator.js +++ b/src/gameobjects/mesh/MeshCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetValue = require('../../utils/object/GetValue'); var Mesh = require('./Mesh'); diff --git a/src/gameobjects/mesh/MeshFactory.js b/src/gameobjects/mesh/MeshFactory.js index 93bd8792c..ec32d85af 100644 --- a/src/gameobjects/mesh/MeshFactory.js +++ b/src/gameobjects/mesh/MeshFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/particles/ParticleManagerCreator.js b/src/gameobjects/particles/ParticleManagerCreator.js index cacc4ad2c..ab53e9a57 100644 --- a/src/gameobjects/particles/ParticleManagerCreator.js +++ b/src/gameobjects/particles/ParticleManagerCreator.js @@ -1,4 +1,4 @@ -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetFastValue = require('../../utils/object/GetFastValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var ParticleEmitterManager = require('./ParticleEmitterManager'); diff --git a/src/gameobjects/particles/ParticleManagerFactory.js b/src/gameobjects/particles/ParticleManagerFactory.js index fa3d73f0a..a6914a998 100644 --- a/src/gameobjects/particles/ParticleManagerFactory.js +++ b/src/gameobjects/particles/ParticleManagerFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/pathfollower/PathFollowerFactory.js b/src/gameobjects/pathfollower/PathFollowerFactory.js index d5e078a75..a14cf2f94 100644 --- a/src/gameobjects/pathfollower/PathFollowerFactory.js +++ b/src/gameobjects/pathfollower/PathFollowerFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/quad/QuadCreator.js b/src/gameobjects/quad/QuadCreator.js index 0c86008bf..283a97d9c 100644 --- a/src/gameobjects/quad/QuadCreator.js +++ b/src/gameobjects/quad/QuadCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Quad = require('./Quad'); diff --git a/src/gameobjects/quad/QuadFactory.js b/src/gameobjects/quad/QuadFactory.js index 9c8aac182..6817a2706 100644 --- a/src/gameobjects/quad/QuadFactory.js +++ b/src/gameobjects/quad/QuadFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/sprite/SpriteCreator.js b/src/gameobjects/sprite/SpriteCreator.js index f3afa5e87..5f9763454 100644 --- a/src/gameobjects/sprite/SpriteCreator.js +++ b/src/gameobjects/sprite/SpriteCreator.js @@ -1,6 +1,6 @@ var BuildGameObject = require('../BuildGameObject'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Sprite = require('./Sprite'); diff --git a/src/gameobjects/sprite/SpriteFactory.js b/src/gameobjects/sprite/SpriteFactory.js index 527ffab39..6bb7700f7 100644 --- a/src/gameobjects/sprite/SpriteFactory.js +++ b/src/gameobjects/sprite/SpriteFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/sprite3d/Sprite3DCreator.js b/src/gameobjects/sprite3d/Sprite3DCreator.js index 353cd066e..008e168ed 100644 --- a/src/gameobjects/sprite3d/Sprite3DCreator.js +++ b/src/gameobjects/sprite3d/Sprite3DCreator.js @@ -1,6 +1,6 @@ var BuildGameObject = require('../BuildGameObject'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Sprite3D = require('./Sprite3D'); diff --git a/src/gameobjects/sprite3d/Sprite3DFactory.js b/src/gameobjects/sprite3d/Sprite3DFactory.js index da0f3b631..548db4d2c 100644 --- a/src/gameobjects/sprite3d/Sprite3DFactory.js +++ b/src/gameobjects/sprite3d/Sprite3DFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/text/static/TextCreator.js b/src/gameobjects/text/static/TextCreator.js index 6f7bc7608..b48135a7e 100644 --- a/src/gameobjects/text/static/TextCreator.js +++ b/src/gameobjects/text/static/TextCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../../BuildGameObject'); -var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../../GameObjectCreator'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var Text = require('./Text'); diff --git a/src/gameobjects/text/static/TextFactory.js b/src/gameobjects/text/static/TextFactory.js index 017066ae9..3217b8d42 100644 --- a/src/gameobjects/text/static/TextFactory.js +++ b/src/gameobjects/text/static/TextFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/tilemap/TilemapCreator.js b/src/gameobjects/tilemap/TilemapCreator.js index 851d56543..23144236b 100644 --- a/src/gameobjects/tilemap/TilemapCreator.js +++ b/src/gameobjects/tilemap/TilemapCreator.js @@ -1,4 +1,4 @@ -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var ParseToTilemap = require('./ParseToTilemap'); // When registering a factory function 'this' refers to the GameObjectCreator context. diff --git a/src/gameobjects/tilemap/TilemapFactory.js b/src/gameobjects/tilemap/TilemapFactory.js index 463aad167..bff646913 100644 --- a/src/gameobjects/tilemap/TilemapFactory.js +++ b/src/gameobjects/tilemap/TilemapFactory.js @@ -1,4 +1,4 @@ -var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); +var GameObjectFactory = require('../GameObjectFactory'); var ParseToTilemap = require('./ParseToTilemap'); // When registering a factory function 'this' refers to the GameObjectFactory context. diff --git a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index 12a351188..8e6675748 100644 --- a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -17,7 +17,6 @@ var DynamicTilemapLayer = new Class({ Components.RenderTarget, Components.ScaleMode, Components.Size, - Components.Texture, Components.Transform, Components.Visible, Components.ScrollFactor, @@ -90,9 +89,7 @@ var DynamicTilemapLayer = new Class({ this.culledTiles = []; this.setAlpha(this.layer.alpha); - this.setTexture(tileset.image.key); this.setPosition(x, y); - this.setSizeToFrame(); this.setOrigin(); this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); }, diff --git a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js index f4e80e87f..cb304ed5c 100644 --- a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js +++ b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js @@ -11,7 +11,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpol var renderTiles = gameObject.culledTiles; var length = renderTiles.length; - var image = gameObject.frame.source.image; + var image = gameObject.tileset.image.getSourceImage(); var tileset = this.tileset; var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX; diff --git a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerWebGLRenderer.js b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerWebGLRenderer.js index bd5cb8001..eaf65a97d 100644 --- a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerWebGLRenderer.js +++ b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerWebGLRenderer.js @@ -12,7 +12,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpola var renderTiles = gameObject.culledTiles; var length = renderTiles.length; var batch = renderer.spriteBatch; - var texture = gameObject.texture.source[0].glTexture; + var texture = gameObject.tileset.image.get().source.glTexture; var textureWidth = texture.width; var textureHeight = texture.height; var tileset = this.tileset; diff --git a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index c6f16dcc8..d1b070b2f 100644 --- a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -18,7 +18,6 @@ var StaticTilemapLayer = new Class({ Components.RenderTarget, Components.ScaleMode, Components.Size, - Components.Texture, Components.Transform, Components.Visible, Components.ScrollFactor, @@ -99,9 +98,7 @@ var StaticTilemapLayer = new Class({ this.vertexCount = 0; this.setAlpha(this.layer.alpha); - this.setTexture(tileset.image.key); this.setPosition(x, y); - this.setSizeToFrame(); this.setOrigin(); 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) { - this.tileTexture = null; this.dirty = true; this.vbo = null; this.gl = renderer.gl; @@ -131,8 +127,8 @@ var StaticTilemapLayer = new Class({ var tileset = this.tileset; var mapWidth = this.layer.width; var mapHeight = this.layer.height; - var width = this.texture.source[0].width; - var height = this.texture.source[0].height; + var width = tileset.image.get().width; + var height = tileset.image.get().height; var mapData = this.layer.data; var tile; diff --git a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerCanvasRenderer.js b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerCanvasRenderer.js index de99a6b03..df394ba3d 100644 --- a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerCanvasRenderer.js +++ b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerCanvasRenderer.js @@ -12,10 +12,9 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, gameObject, interpola var renderTiles = gameObject.culledTiles; var tileset = this.tileset; - var frame = gameObject.frame; var ctx = renderer.gameContext; var tileCount = renderTiles.length; - var image = frame.source.image; + var image = tileset.image.getSourceImage(); var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX; var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY; diff --git a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerWebGLRenderer.js b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerWebGLRenderer.js index 5c7b09c42..6531ffd88 100644 --- a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerWebGLRenderer.js +++ b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerWebGLRenderer.js @@ -8,10 +8,10 @@ var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPerc } var gameObject = src; - var frame = gameObject.frame; 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.upload(camera); diff --git a/src/gameobjects/tilesprite/TileSpriteCreator.js b/src/gameobjects/tilesprite/TileSpriteCreator.js index 4cd2279e3..e933f7549 100644 --- a/src/gameobjects/tilesprite/TileSpriteCreator.js +++ b/src/gameobjects/tilesprite/TileSpriteCreator.js @@ -1,5 +1,5 @@ var BuildGameObject = require('../BuildGameObject'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var TileSprite = require('./TileSprite'); diff --git a/src/gameobjects/tilesprite/TileSpriteFactory.js b/src/gameobjects/tilesprite/TileSpriteFactory.js index 787bd7cec..d4ea4603a 100644 --- a/src/gameobjects/tilesprite/TileSpriteFactory.js +++ b/src/gameobjects/tilesprite/TileSpriteFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/gameobjects/zone/ZoneCreator.js b/src/gameobjects/zone/ZoneCreator.js index ea3d7a0c3..f48b5d024 100644 --- a/src/gameobjects/zone/ZoneCreator.js +++ b/src/gameobjects/zone/ZoneCreator.js @@ -1,4 +1,4 @@ -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); +var GameObjectCreator = require('../GameObjectCreator'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Zone = require('./Zone'); diff --git a/src/gameobjects/zone/ZoneFactory.js b/src/gameobjects/zone/ZoneFactory.js index 74506c7fe..0547c1d2d 100644 --- a/src/gameobjects/zone/ZoneFactory.js +++ b/src/gameobjects/zone/ZoneFactory.js @@ -1,5 +1,5 @@ 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. // diff --git a/src/geom/ellipse/Circumference.js b/src/geom/ellipse/Circumference.js index 598b8db3a..937451a6c 100644 --- a/src/geom/ellipse/Circumference.js +++ b/src/geom/ellipse/Circumference.js @@ -10,8 +10,8 @@ */ var Circumference = function (ellipse) { - var rx = ellipse.width; - var ry = ellipse.height; + var rx = ellipse.width / 2; + var ry = ellipse.height / 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))))); diff --git a/src/geom/ellipse/Contains.js b/src/geom/ellipse/Contains.js index da1c8cf06..39af14c41 100644 --- a/src/geom/ellipse/Contains.js +++ b/src/geom/ellipse/Contains.js @@ -16,14 +16,14 @@ var Contains = function (ellipse, x, y) { return false; } - + // 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 normy = ((y - ellipse.y) / ellipse.height) - 0.5; - + var normx = ((x - ellipse.x) / ellipse.width); + var normy = ((y - ellipse.y) / ellipse.height); + normx *= normx; normy *= normy; - + return (normx + normy < 0.25); }; diff --git a/src/geom/ellipse/GetBounds.js b/src/geom/ellipse/GetBounds.js index cfc5b9bd9..9bf380e65 100644 --- a/src/geom/ellipse/GetBounds.js +++ b/src/geom/ellipse/GetBounds.js @@ -15,8 +15,8 @@ var GetBounds = function (ellipse, out) { if (out === undefined) { out = new Rectangle(); } - out.x = ellipse.x - ellipse.width; - out.y = ellipse.y - ellipse.height; + out.x = ellipse.left; + out.y = ellipse.top; out.width = ellipse.width; out.height = ellipse.height; diff --git a/src/input/InputPlugin.js b/src/input/InputPlugin.js index 3c2c6fdc3..97efcfe31 100644 --- a/src/input/InputPlugin.js +++ b/src/input/InputPlugin.js @@ -10,6 +10,7 @@ var Rectangle = require('../geom/rectangle/Rectangle'); var RectangleContains = require('../geom/rectangle/Contains'); var Triangle = require('../geom/triangle/Triangle'); var TriangleContains = require('../geom/triangle/Contains'); +var PluginManager = require('../plugins/PluginManager'); // Drag Events // 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 this.scene = scene; + this.systems = scene.sys; + + this.mapping = 'input'; + + this.systems.events.on('boot', this.boot, this); + // InputManager 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' ]; }, - activePointer: { + boot: function () + { + this.systems.inject(this); - get: function () - { - return this.manager.activePointer; - } + 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.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. - // 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 () + preUpdate: function () { var removeList = this._pendingRemoval; var insertList = this._pendingInsertion; @@ -156,13 +148,6 @@ var InputPlugin = new Class({ this._list = current.concat(insertList.splice(0)); }, - boot: function () - { - this.cameras = this.scene.sys.cameras; - - this.displayList = this.scene.sys.displayList; - }, - clear: function (gameObject) { 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. // 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 { @@ -988,8 +973,39 @@ var InputPlugin = new Class({ this.keyboard = undefined; this.mouse = 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; diff --git a/src/input/index.js b/src/input/index.js index 9305e71c4..f9f210bde 100644 --- a/src/input/index.js +++ b/src/input/index.js @@ -3,6 +3,8 @@ module.exports = { Gamepad: require('./gamepad'), + InputManager: require('./InputManager'), + InputPlugin: require('./InputPlugin'), InteractiveObject: require('./InteractiveObject'), Keyboard: require('./keyboard'), Mouse: require('./mouse'), diff --git a/src/scene/plugins/Loader.js b/src/loader/Loader.js similarity index 82% rename from src/scene/plugins/Loader.js rename to src/loader/Loader.js index c5b5df4b1..aac49a19b 100644 --- a/src/scene/plugins/Loader.js +++ b/src/loader/Loader.js @@ -1,26 +1,28 @@ -var BaseLoader = require('../../loader/BaseLoader'); -var Class = require('../../utils/Class'); -var CONST = require('../../loader/const'); -var NumberArray = require('../../utils/array/NumberArray'); +var BaseLoader = require('./BaseLoader'); +var Class = require('../utils/Class'); +var CONST = require('./const'); +var NumberArray = require('../utils/array/NumberArray'); +var PluginManager = require('../plugins/PluginManager'); -var AnimationJSONFile = require('../../loader/filetypes/AnimationJSONFile'); -var AtlasJSONFile = require('../../loader/filetypes/AtlasJSONFile'); -var AudioFile = require('../../loader/filetypes/AudioFile'); -var BinaryFile = require('../../loader/filetypes/BinaryFile'); -var BitmapFontFile = require('../../loader/filetypes/BitmapFontFile'); -var GLSLFile = require('../../loader/filetypes/GLSLFile'); -var HTMLFile = require('../../loader/filetypes/HTMLFile'); -var ImageFile = require('../../loader/filetypes/ImageFile'); -var JSONFile = require('../../loader/filetypes/JSONFile'); -var ScriptFile = require('../../loader/filetypes/ScriptFile'); -var SpriteSheet = require('../../loader/filetypes/SpriteSheet'); -var SVGFile = require('../../loader/filetypes/SVGFile'); -var TextFile = require('../../loader/filetypes/TextFile'); -var TilemapCSVFile = require('../../loader/filetypes/TilemapCSVFile'); -var TilemapJSONFile = require('../../loader/filetypes/TilemapJSONFile'); -var UnityAtlasFile = require('../../loader/filetypes/UnityAtlasFile'); -var WavefrontFile = require('../../loader/filetypes/WavefrontFile'); -var XMLFile = require('../../loader/filetypes/XMLFile'); +// TODO - Injection mapped +var AnimationJSONFile = require('./filetypes/AnimationJSONFile'); +var AtlasJSONFile = require('./filetypes/AtlasJSONFile'); +var AudioFile = require('./filetypes/AudioFile'); +var BinaryFile = require('./filetypes/BinaryFile'); +var BitmapFontFile = require('./filetypes/BitmapFontFile'); +var GLSLFile = require('./filetypes/GLSLFile'); +var HTMLFile = require('./filetypes/HTMLFile'); +var ImageFile = require('./filetypes/ImageFile'); +var JSONFile = require('./filetypes/JSONFile'); +var ScriptFile = require('./filetypes/ScriptFile'); +var SpriteSheet = require('./filetypes/SpriteSheet'); +var SVGFile = require('./filetypes/SVGFile'); +var TextFile = require('./filetypes/TextFile'); +var TilemapCSVFile = require('./filetypes/TilemapCSVFile'); +var TilemapJSONFile = require('./filetypes/TilemapJSONFile'); +var UnityAtlasFile = require('./filetypes/UnityAtlasFile'); +var WavefrontFile = require('./filetypes/WavefrontFile'); +var XMLFile = require('./filetypes/XMLFile'); var Loader = new Class({ @@ -32,9 +34,23 @@ var Loader = new Class({ { BaseLoader.call(this, scene); + this.systems = scene.sys; + + this.mapping = 'load'; + + this.systems.events.on('boot', this.boot, this); + 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 image: function (key, url, xhrSettings) @@ -294,8 +310,15 @@ var Loader = new Class({ } return entry; + }, + + shutdown: function () + { + } }); +PluginManager.register('load', Loader); + module.exports = Loader; diff --git a/src/loader/index.js b/src/loader/index.js new file mode 100644 index 000000000..5f9553ee5 --- /dev/null +++ b/src/loader/index.js @@ -0,0 +1,9 @@ +// Phaser.Loader + +module.exports = { + + BaseLoader: require('./BaseLoader'), + File: require('./File'), + LoaderPlugin: require('./Loader') + +}; diff --git a/src/phaser.js b/src/phaser.js index 5efb3a356..96bfc6846 100644 --- a/src/phaser.js +++ b/src/phaser.js @@ -8,46 +8,29 @@ var Extend = require('./utils/object/Extend'); var Phaser = { Actions: require('./actions/'), - - Create: require('./create/'), - + Animation: require('./animations/'), + Cache: require('./cache/'), 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'), - - Utils: require('./utils') + Create: require('./create/'), + 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/') }; diff --git a/src/physics/arcade/Arcade.js b/src/physics/arcade/Arcade.js deleted file mode 100644 index 14d65171b..000000000 --- a/src/physics/arcade/Arcade.js +++ /dev/null @@ -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; diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js new file mode 100644 index 000000000..cb16fbd50 --- /dev/null +++ b/src/physics/arcade/ArcadePhysics.js @@ -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; diff --git a/src/physics/arcade/World.js b/src/physics/arcade/World.js index d04900f55..cc5857d12 100644 --- a/src/physics/arcade/World.js +++ b/src/physics/arcade/World.js @@ -1,5 +1,3 @@ -// Phaser.Physics.Arcade.World - var Body = require('./Body'); var Class = require('../../utils/Class'); var Collider = require('./Collider'); @@ -13,6 +11,8 @@ var Set = require('../../structs/Set'); var StaticBody = require('./StaticBody'); var Vector2 = require('../../math/Vector2'); +// Phaser.Physics.Arcade.World + var World = new Class({ Extends: EventEmitter, @@ -399,16 +399,6 @@ var World = new Class({ collideGroupVsTilemapLayer: require('./inc/CollideGroupVsTilemapLayer'), 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 collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly) { diff --git a/src/physics/arcade/inc/CollideSpriteVsTilemapLayer.js b/src/physics/arcade/inc/CollideSpriteVsTilemapLayer.js index ea113bda9..0c1f6d04d 100644 --- a/src/physics/arcade/inc/CollideSpriteVsTilemapLayer.js +++ b/src/physics/arcade/inc/CollideSpriteVsTilemapLayer.js @@ -11,10 +11,30 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac return false; } - var mapData = tilemapLayer.getTilesWithinWorldXY( - body.position.x, body.position.y, - body.width, body.height - ); + var x = body.position.x; + var y = body.position.y; + 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) { @@ -29,6 +49,14 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac tile = mapData[i]; tileWorldRect.left = tilemapLayer.tileToWorldX(tile.x); 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.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY; diff --git a/src/physics/arcade/inc/tilemap/SeparateTile.js b/src/physics/arcade/inc/tilemap/SeparateTile.js index 2ea374933..79ceb8d61 100644 --- a/src/physics/arcade/inc/tilemap/SeparateTile.js +++ b/src/physics/arcade/inc/tilemap/SeparateTile.js @@ -55,7 +55,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia { 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 if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body)) @@ -66,14 +66,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia if (faceVertical) { - oy = TileCheckY(body, tile, tilemapLayer, tileBias); + oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias); } } else { 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 if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body)) @@ -84,7 +84,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia if (faceHorizontal) { - ox = TileCheckX(body, tile, tilemapLayer, tileBias); + ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias); } } diff --git a/src/physics/arcade/inc/tilemap/TileCheckX.js b/src/physics/arcade/inc/tilemap/TileCheckX.js index 92258db5e..2e5a3cc18 100644 --- a/src/physics/arcade/inc/tilemap/TileCheckX.js +++ b/src/physics/arcade/inc/tilemap/TileCheckX.js @@ -10,12 +10,9 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX'); * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @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 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) { diff --git a/src/physics/arcade/inc/tilemap/TileCheckY.js b/src/physics/arcade/inc/tilemap/TileCheckY.js index 282a20aca..3bcfea7e4 100644 --- a/src/physics/arcade/inc/tilemap/TileCheckY.js +++ b/src/physics/arcade/inc/tilemap/TileCheckY.js @@ -10,12 +10,9 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY'); * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @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 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) { diff --git a/src/physics/arcade/index.js b/src/physics/arcade/index.js index afe9c5405..c489a2276 100644 --- a/src/physics/arcade/index.js +++ b/src/physics/arcade/index.js @@ -1,15 +1,16 @@ // Phaser.Physics.Arcade -// World updated to run off the Phaser main loop. -// Body extended to support additional setter functions. - module.exports = { + ArcadePhysics: require('./ArcadePhysics'), Body: require('./Body'), + Collider: require('./Collider'), Factory: require('./Factory'), Group: require('./PhysicsGroup'), Image: require('./ArcadeImage'), Sprite: require('./ArcadeSprite'), + StaticBody: require('./StaticBody'), + StaticGroup: require('./StaticPhysicsGroup'), World: require('./World') }; diff --git a/src/physics/impact/Impact.js b/src/physics/impact/Impact.js deleted file mode 100644 index 44cb7645b..000000000 --- a/src/physics/impact/Impact.js +++ /dev/null @@ -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; diff --git a/src/physics/impact/ImpactPhysics.js b/src/physics/impact/ImpactPhysics.js new file mode 100644 index 000000000..5f2f973af --- /dev/null +++ b/src/physics/impact/ImpactPhysics.js @@ -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; diff --git a/src/physics/impact/World.js b/src/physics/impact/World.js index d0562de2e..f53a2c59e 100644 --- a/src/physics/impact/World.js +++ b/src/physics/impact/World.js @@ -216,11 +216,6 @@ var World = new Class({ return this; }, - postUpdate: function () - { - // NOOP - }, - update: function (time, delta) { if (!this.enabled || this.bodies.size === 0) diff --git a/src/physics/impact/index.js b/src/physics/impact/index.js index 275225079..4716a113c 100644 --- a/src/physics/impact/index.js +++ b/src/physics/impact/index.js @@ -15,10 +15,14 @@ module.exports = { Body: require('./Body'), + Body: require('./ImpactBody'), COLLIDES: require('./COLLIDES'), CollisionMap: require('./CollisionMap'), + Factory: require('./Factory'), + Image: require('./ImpactImage'), + ImpactPhysics: require('./ImpactPhysics'), + Sprite: require('./ImpactSprite'), TYPE: require('./TYPE'), - World: require('./World'), - Factory: require('./Factory') + World: require('./World') }; diff --git a/src/physics/index.js b/src/physics/index.js index 86b2fa616..096f30cd3 100644 --- a/src/physics/index.js +++ b/src/physics/index.js @@ -1,8 +1,10 @@ // Phaser.Physics module.exports = { + Arcade: require('./arcade'), Impact: require('./impact'), - Matter: require('./matter-js/CustomMain'), + Matter: require('./matter-js'), PolyDecomp: require('./poly-decomp') + }; diff --git a/src/physics/matter-js/Matter.js b/src/physics/matter-js/Matter.js deleted file mode 100644 index 32e85313a..000000000 --- a/src/physics/matter-js/Matter.js +++ /dev/null @@ -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; diff --git a/src/physics/matter-js/MatterPhysics.js b/src/physics/matter-js/MatterPhysics.js new file mode 100644 index 000000000..95a893d6e --- /dev/null +++ b/src/physics/matter-js/MatterPhysics.js @@ -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; diff --git a/src/physics/matter-js/World.js b/src/physics/matter-js/World.js index a77ad126e..18d945359 100644 --- a/src/physics/matter-js/World.js +++ b/src/physics/matter-js/World.js @@ -307,36 +307,38 @@ var World = new Class({ postUpdate: function () { - if (this.drawDebug) + if (!this.drawDebug) { - var graphics = this.debugGraphic; - var bodies = Composite.allBodies(this.localWorld); + return; + } - graphics.clear(); - graphics.lineStyle(1, this.defaults.bodyDebugColor); + var graphics = this.debugGraphic; + 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]; - - 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(); + 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(); } }, @@ -362,7 +364,6 @@ var World = new Class({ destroy: function () { - // TODO this.shutdown(); } diff --git a/src/physics/matter-js/index.js b/src/physics/matter-js/index.js new file mode 100644 index 000000000..813aa2874 --- /dev/null +++ b/src/physics/matter-js/index.js @@ -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') + +}; diff --git a/src/plugins/PluginManager.js b/src/plugins/PluginManager.js index 99991ac59..d3a1e3ce7 100644 --- a/src/plugins/PluginManager.js +++ b/src/plugins/PluginManager.js @@ -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; - 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 - sys[p] = new plugins[p](scene); + sys[pluginKey] = new plugins[pluginKey](scene); } } }, @@ -52,7 +61,7 @@ PluginManager.register = function (key, plugin) { plugins[key] = plugin; - console.log('PluginManager.register', key); + // console.log('PluginManager.register', key); }; module.exports = PluginManager; diff --git a/src/scene/local/InjectionMap.js b/src/scene/InjectionMap.js similarity index 64% rename from src/scene/local/InjectionMap.js rename to src/scene/InjectionMap.js index 4cee37874..f5ea9db8e 100644 --- a/src/scene/local/InjectionMap.js +++ b/src/scene/InjectionMap.js @@ -1,5 +1,5 @@ // 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 var InjectionMap = { @@ -14,14 +14,16 @@ var InjectionMap = { add: 'add', cameras: 'cameras', + children: 'displayList', data: 'data', - displayList: 'children', events: 'events', - inputManager: 'input', + impact: 'impactPhysics', + input: 'input', load: 'load', make: 'make', - physicsManager: 'physics', - sceneManager: 'scene', + matter: 'matterPhysics', + physics: 'arcadePhysics', + scene: 'sceneManager', time: 'time', tweens: 'tweens' diff --git a/src/scene/local/Scene.js b/src/scene/Scene.js similarity index 91% rename from src/scene/local/Scene.js rename to src/scene/Scene.js index 162ae5b3b..0bb97999a 100644 --- a/src/scene/local/Scene.js +++ b/src/scene/Scene.js @@ -1,5 +1,4 @@ - -var Class = require('../../utils/Class'); +var Class = require('../utils/Class'); var Systems = require('./Systems'); var Scene = new Class({ diff --git a/src/scene/SceneManager.js b/src/scene/SceneManager.js index e9625e1bc..49135b25d 100644 --- a/src/scene/SceneManager.js +++ b/src/scene/SceneManager.js @@ -4,8 +4,8 @@ var Class = require('../utils/Class'); var CONST = require('../const'); var GetValue = require('../utils/object/GetValue'); var NOOP = require('../utils/NOOP'); -var Scene = require('./local/Scene'); -var Systems = require('./local/Systems'); +var Scene = require('./Scene'); +var Systems = require('./Systems'); var SceneManager = new Class({ diff --git a/src/scene/plugins/SceneManager.js b/src/scene/ScenePlugin.js similarity index 96% rename from src/scene/plugins/SceneManager.js rename to src/scene/ScenePlugin.js index da0eddd45..9d5655176 100644 --- a/src/scene/plugins/SceneManager.js +++ b/src/scene/ScenePlugin.js @@ -1,5 +1,5 @@ -var Class = require('../../utils/Class'); -var PluginManager = require('../../plugins/PluginManager'); +var Class = require('../utils/Class'); +var PluginManager = require('../plugins/PluginManager'); // A proxy class to the Global Scene Manager var SceneManager = new Class({ @@ -32,11 +32,12 @@ var SceneManager = new Class({ { this.systems.inject(this); + this.systems.events.on('preupdate', this.preUpdate, this); this.systems.events.on('shutdown', this.shutdown, this); this.systems.events.on('destroy', this.destroy, this); }, - update: function () + preUpdate: function () { var len = this._queue.length; diff --git a/src/scene/local/Settings.js b/src/scene/Settings.js similarity index 91% rename from src/scene/local/Settings.js rename to src/scene/Settings.js index 09eed118a..d2d96a5e2 100644 --- a/src/scene/local/Settings.js +++ b/src/scene/Settings.js @@ -1,6 +1,6 @@ -var CONST = require('../const'); -var ScaleModes = require('../../renderer/ScaleModes'); -var GetValue = require('../../utils/object/GetValue'); +var CONST = require('./const'); +var ScaleModes = require('../renderer/ScaleModes'); +var GetValue = require('../utils/object/GetValue'); var InjectionMap = require('./InjectionMap'); var Settings = { diff --git a/src/scene/local/Systems.js b/src/scene/Systems.js similarity index 50% rename from src/scene/local/Systems.js rename to src/scene/Systems.js index 0cd228346..5447459f8 100644 --- a/src/scene/local/Systems.js +++ b/src/scene/Systems.js @@ -1,21 +1,8 @@ -// var CameraManager = require('../../camera/local/CameraManager'); -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 Class = require('../utils/Class'); var EventEmitter = require('eventemitter3'); -var GameObjectCreator = require('../plugins/GameObjectCreator'); -var GameObjectFactory = require('../plugins/GameObjectFactory'); -var InputManager = require('../../input/InputPlugin'); -var Loader = require('../plugins/Loader'); -var PhysicsManager = require('../plugins/PhysicsManager'); -var SceneManager = require('../plugins/SceneManager'); +var GetFastValue = require('../utils/object/GetFastValue'); +var ScenePlugin = require('./ScenePlugin'); var Settings = require('./Settings'); -var TweenManager = require('../../tweens/manager/TweenManager'); -var UpdateList = require('../plugins/UpdateList'); - -var TestPlugin = require('../../plugins/TestPlugin'); var Systems = new Class({ @@ -31,7 +18,7 @@ var Systems = new Class({ 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.context; @@ -74,27 +61,55 @@ var Systems = new Class({ 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' ]); - - this.data = new Data(scene); - 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 + if (physics) + { + game.plugins.install(scene, [], physics); + } this.events.emit('boot', this); + }, - this.inputManager.boot(); - this.physicsManager.boot(); + getPhysicsSystem: function () + { + 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) @@ -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) { - // Are there any pending SceneManager actions? - // This plugin is a special case, as it can literally modify this Scene, so we update it directly. - this.sceneManager.update(); + this.events.emit('preupdate', time, delta); if (!this.settings.active) { return; } - this.events.emit('preupdate', time, delta); - - this.tweens.begin(time); - this.inputManager.begin(time); - 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.events.emit('postupdate', time, delta); - - this.physicsManager.postUpdate(); }, 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 pause: function () { - // Was paused by the GlobalSceneManager + // Was paused by the SceneManager this.settings.active = false; - if (this.scene.pause) - { - this.scene.pause.call(this.scene); - } + this.events.emit('pause', this); }, resume: function () { - // Was resumed by the GlobalSceneManager + // Was resumed by the SceneManager this.settings.active = true; - if (this.scene.resume) - { - this.scene.resume.call(this.scene); - } + this.events.emit('resume', this); }, sleep: function () { - // Was sent to sleep by the GlobalSceneManager + // Was sent to sleep by the SceneManager this.settings.active = false; this.settings.visible = false; - if (this.scene.sleep) - { - this.scene.sleep.call(this.scene); - } + this.events.emit('sleep', this); }, wake: function () { - // Was woken up by the GlobalSceneManager + // Was woken up by the SceneManager this.settings.active = true; this.settings.visible = true; - if (this.scene.wake) - { - this.scene.wake.call(this.scene); - } + this.events.emit('wake', this); }, start: function (data) { - // Was started by the GlobalSceneManager + // Was started by the SceneManager this.settings.data = data; this.settings.active = true; this.settings.visible = true; + + this.events.emit('start', this); }, shutdown: function () { - // Was stopped by the GlobalSceneManager + // Was stopped by the SceneManager this.settings.active = false; this.settings.visible = false; 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 () { 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); - } } }); diff --git a/src/scene/plugins/PhysicsManager.js b/src/scene/plugins/PhysicsManager.js deleted file mode 100644 index 328375fc8..000000000 --- a/src/scene/plugins/PhysicsManager.js +++ /dev/null @@ -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; diff --git a/src/textures/index.js b/src/textures/index.js new file mode 100644 index 000000000..1861bafb1 --- /dev/null +++ b/src/textures/index.js @@ -0,0 +1,11 @@ +// Phaser.Textures + +module.exports = { + + FilterMode: require('./FilterMode'), + Frame: require('./Frame'), + Texture: require('./Texture'), + TextureManager: require('./TextureManager'), + TextureSource: require('./TextureSource') + +}; diff --git a/src/tweens/timeline/Timeline.js b/src/tweens/Timeline.js similarity index 98% rename from src/tweens/timeline/Timeline.js rename to src/tweens/Timeline.js index e49b2e33c..0f59fa6ae 100644 --- a/src/tweens/timeline/Timeline.js +++ b/src/tweens/Timeline.js @@ -1,6 +1,6 @@ -var Class = require('../../utils/Class'); -var TweenBuilder = require('../builder/TweenBuilder'); -var TWEEN_CONST = require('../tween/const'); +var Class = require('../utils/Class'); +var TweenBuilder = require('./builder/TweenBuilder'); +var TWEEN_CONST = require('./tween/const'); // Phaser.Tweens.Timeline diff --git a/src/tweens/manager/TweenManager.js b/src/tweens/TweenManager.js similarity index 91% rename from src/tweens/manager/TweenManager.js rename to src/tweens/TweenManager.js index 84a74b566..f104f3d23 100644 --- a/src/tweens/manager/TweenManager.js +++ b/src/tweens/TweenManager.js @@ -1,8 +1,9 @@ -var Class = require('../../utils/Class'); -var TimelineBuilder = require('../builder/TimelineBuilder'); -var TweenBuilder = require('../builder/TweenBuilder'); -var NumberTweenBuilder = require('../builder/NumberTweenBuilder'); -var TWEEN_CONST = require('../tween/const'); +var Class = require('../utils/Class'); +var NumberTweenBuilder = require('./builder/NumberTweenBuilder'); +var PluginManager = require('../plugins/PluginManager'); +var TimelineBuilder = require('./builder/TimelineBuilder'); +var TWEEN_CONST = require('./tween/const'); +var TweenBuilder = require('./builder/TweenBuilder'); // Phaser.Tweens.TweenManager @@ -12,9 +13,15 @@ var TweenManager = new Class({ 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.systems = scene.sys; + + this.mapping = 'tweens'; + + this.systems.events.on('boot', this.boot, this); + this.timeScale = 1; this._add = []; @@ -25,9 +32,15 @@ var TweenManager = new Class({ this._toProcess = 0; }, - // Scene is starting up 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; }, @@ -92,7 +105,7 @@ var TweenManager = new Class({ return tween; }, - begin: function () + preUpdate: function () { if (this._toProcess === 0) { @@ -466,4 +479,6 @@ var TweenManager = new Class({ }); +PluginManager.register('tweens', TweenManager); + module.exports = TweenManager; diff --git a/src/tweens/builder/TimelineBuilder.js b/src/tweens/builder/TimelineBuilder.js index 5d1ea5b87..3bb3b8412 100644 --- a/src/tweens/builder/TimelineBuilder.js +++ b/src/tweens/builder/TimelineBuilder.js @@ -7,7 +7,7 @@ var GetTargets = require('./GetTargets'); var GetTweens = require('./GetTweens'); var GetValue = require('../../utils/object/GetValue'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); -var Timeline = require('../timeline/Timeline'); +var Timeline = require('../Timeline'); var TweenBuilder = require('./TweenBuilder'); // Phaser.Tweens.TimelineBuilder diff --git a/src/tweens/index.js b/src/tweens/index.js index 1e8e7c467..554a4f6f5 100644 --- a/src/tweens/index.js +++ b/src/tweens/index.js @@ -2,9 +2,9 @@ module.exports = { - TweenManager: require('./manager/TweenManager'), + TweenManager: require('./TweenManager'), Tween: require('./tween/Tween'), TweenData: require('./tween/TweenData'), - Timeline: require('./timeline/Timeline') + Timeline: require('./Timeline') }; diff --git a/src/tweens/tween/Tween.js b/src/tweens/tween/Tween.js index f9ab88ab8..341c4b7a2 100644 --- a/src/tweens/tween/Tween.js +++ b/src/tweens/tween/Tween.js @@ -1,6 +1,6 @@ var Class = require('../../utils/Class'); -var GameObjectCreator = require('../../scene/plugins/GameObjectCreator'); -var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); +var GameObjectCreator = require('../../gameobjects/GameObjectCreator'); +var GameObjectFactory = require('../../gameobjects/GameObjectFactory'); var TWEEN_CONST = require('./const'); // Phaser.Tweens.Tween