diff --git a/examples/js.php b/examples/js.php index f7f68c74..1fc6ee23 100644 --- a/examples/js.php +++ b/examples/js.php @@ -42,19 +42,22 @@ - - + + + + + + + + - - - - + - + @@ -67,5 +70,3 @@ - - diff --git a/examples/stage 1.php b/examples/stage 1.php index 689513c9..b90f8c86 100644 --- a/examples/stage 1.php +++ b/examples/stage 1.php @@ -12,37 +12,27 @@ (function () { - // var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); - var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update }); + var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }, false, true); var bunny; function preload() { - - console.log('***> preload called'); - game.load.image('cockpit', 'assets/pics/cockpit.png'); - game.load.image('overdose', 'assets/pics/lance-overdose-loader_eye.png'); - + game.load.image('bunny', 'assets/sprites/bunny.png'); } function create() { - console.log('***> create called'); - - // Create a basetexture - var base = new PIXI.BaseTexture(game.cache.getImage('overdose')); + var base = new PIXI.BaseTexture(game.cache.getImage('bunny')); var texture = new PIXI.Texture(base); bunny = new PIXI.Sprite(texture); - // center the sprites anchor point bunny.anchor.x = 0.5; bunny.anchor.y = 0.5; - // move the sprite t the center of the screen - bunny.position.x = 200; - bunny.position.y = 150; + bunny.position.x = game.world.centerX; + bunny.position.y = game.world.centerY; - game.stage._s.addChild(bunny); + game.world.add(bunny); } @@ -50,9 +40,9 @@ if (game.paused == false) { - bunny.rotation += 0.1; - bunny.scale.x += 0.01; - bunny.scale.y += 0.01; + bunny.rotation += 0.01; + // bunny.scale.x += 0.01; + // bunny.scale.y += 0.01; } } diff --git a/src/Game.js b/src/core/Game.js similarity index 97% rename from src/Game.js rename to src/core/Game.js index 4da146a9..d3ef6644 100644 --- a/src/Game.js +++ b/src/core/Game.js @@ -257,13 +257,12 @@ Phaser.Game.prototype = { this.isBooted = true; this.device = new Phaser.Device(); + this.math = Phaser.Math; this.setUpRenderer(); - this.net = new Phaser.Net(this); - this.math = Phaser.Math; + this.world = new Phaser.World(this); this.stage = new Phaser.Stage(this); - // this.world = new Phaser.World(this, width, height); // this.add = new Phaser.GameObjectFactory(this); this.cache = new Phaser.Cache(this); this.load = new Phaser.Loader(this); @@ -274,11 +273,11 @@ Phaser.Game.prototype = { this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]); // this.physics = new Phaser.Physics.PhysicsManager(this); this.plugins = new Phaser.PluginManager(this, this); + this.net = new Phaser.Net(this); this.load.onLoadComplete.add(this.loadComplete, this); this.state.boot(); - // this.world.boot(); this.stage.boot(); // this.input.boot(); @@ -309,7 +308,7 @@ Phaser.Game.prototype = { { this.renderType = Phaser.CANVAS; this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, this.transparent); - Phaser.Canvas.setSmoothingEnabled(this.renderer.view, this.antialias); + Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); } else { @@ -368,7 +367,7 @@ Phaser.Game.prototype = { this.state.preRender(); - this.renderer.render(this.stage._s); + this.renderer.render(this.world._stage); this.plugins.render(); @@ -385,7 +384,7 @@ Phaser.Game.prototype = { this.plugins.postUpdate(); this.plugins.preRender(); - this.renderer.render(this.stage._s); + this.renderer.render(this.world._stage); this.plugins.render(); this.state.loadRender(); this.plugins.postRender(); diff --git a/src/Stage.js b/src/core/Stage.js similarity index 97% rename from src/Stage.js rename to src/core/Stage.js index 4ee7c27c..4b621e4c 100644 --- a/src/Stage.js +++ b/src/core/Stage.js @@ -18,7 +18,6 @@ Phaser.Stage = function (game) { Phaser.Stage.prototype = { _onChange: null, - _s: null, bounds: null, offset: null, @@ -30,8 +29,6 @@ Phaser.Stage.prototype = { Phaser.Canvas.getOffset(this.game.renderer.view, this.offset); this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height); - this._s = new PIXI.Stage(0x000000); - var _this = this; this._onChange = function (event) { diff --git a/src/core/World.js b/src/core/World.js new file mode 100644 index 00000000..eee66652 --- /dev/null +++ b/src/core/World.js @@ -0,0 +1,116 @@ +Phaser.World = function (game) { + + this.game = game; + this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height); + + this._stage = new PIXI.Stage(0x000000); + + this._container = new PIXI.DisplayObjectContainer(); + + this._stage.addChild(this._container); + +}; + +Phaser.World.prototype = { + + _stage: null, + _container: null, + + bounds: null, + + add: function (sprite) { + this._container.addChild(sprite); + }, + + /** + * Updates the size of this world. + * + * @param width {number} New width of the world. + * @param height {number} New height of the world. + * @param [updateCameraBounds] {bool} Update camera bounds automatically or not. Default to true. + */ + setSize: function (width, height, updateCameraBounds) { + + if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; } + + this.bounds.width = width; + this.bounds.height = height; + + if (updateCameraBounds == true) + { + // this.game.camera.setBounds(0, 0, width, height); + } + + }, + +}; + +// Getters / Setters + +Object.defineProperty(Phaser.World.prototype, "width", { + + get: function () { + return this.bounds.width; + }, + + set: function (value) { + this.bounds.width = value; + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Phaser.World.prototype, "height", { + + get: function () { + return this.bounds.height; + }, + + set: function (value) { + this.bounds.height = value; + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Phaser.World.prototype, "centerX", { + + get: function () { + return this.bounds.halfWidth; + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Phaser.World.prototype, "centerY", { + + get: function () { + return this.bounds.halfHeight; + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Phaser.World.prototype, "randomX", { + + get: function () { + return Math.round(Math.random() * this.bounds.width); + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Phaser.World.prototype, "randomY", { + + get: function () { + return Math.round(Math.random() * this.bounds.height); + }, + + enumerable: true, + configurable: true +});