diff --git a/examples/display/fullscreen.js b/examples/display/fullscreen.js index 2ff001d7..17c3f629 100644 --- a/examples/display/fullscreen.js +++ b/examples/display/fullscreen.js @@ -3,22 +3,25 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: function preload() { - game.load.image('atari1', 'assets/sprites/atari130xe.png'); + game.load.image('dragon', 'assets/pics/cougar_dragonsun.png'); } function create() { - var sprite = game.add.sprite(0, 0, 'atari1'); + var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon'); + sprite.anchor.set(0.5); - game.stage.backgroundColor = '#e3ed49'; + game.stage.backgroundColor = '#000'; // Stretch to fill -// game.stage.fullScreenScaleMode = Phaser.StageScaleMode.EXACT_FIT; + game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; + // Keep original size -// game.stage.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE; + // game.scale.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE; + // Maintain aspect ratio - game.stage.fullScreenScaleMode = Phaser.StageScaleMode.SHOW_ALL; + // game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; game.input.onDown.add(gofull, this); @@ -32,16 +35,10 @@ function gofull() { function update() { - if (document.getElementsByTagName('body')[0].scrollTop > 1000) - { - game.stage.backgroundColor = '#87ff55'; - window.scrollTo(0, 0); - } - } function render () { - game.debug.renderText('Tap to go fullscreen', 32, 150); + game.debug.renderText('Click / Tap to go fullscreen', 270, 16); } diff --git a/examples/wip/fullscreen.js b/examples/wip/fullscreen.js new file mode 100644 index 00000000..17c3f629 --- /dev/null +++ b/examples/wip/fullscreen.js @@ -0,0 +1,44 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('dragon', 'assets/pics/cougar_dragonsun.png'); + +} + +function create() { + + var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon'); + sprite.anchor.set(0.5); + + game.stage.backgroundColor = '#000'; + + // Stretch to fill + game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; + + // Keep original size + // game.scale.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE; + + // Maintain aspect ratio + // game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; + + game.input.onDown.add(gofull, this); + +} + +function gofull() { + + game.scale.startFullScreen(); + +} + +function update() { + +} + +function render () { + + game.debug.renderText('Click / Tap to go fullscreen', 270, 16); + +} diff --git a/src/core/Game.js b/src/core/Game.js index 861a2b85..2cbdb0b8 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -246,13 +246,6 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant */ this._codePaused = false; - /** - * @property {boolean} _loadComplete - Whether load complete loading or not. - * @private - * @default - */ - this._loadComplete = false; - // Parse the configuration object (if any) if (arguments.length === 1 && typeof arguments[0] === 'object') { @@ -328,12 +321,12 @@ Phaser.Game.prototype = { if (config['width']) { - this.width = this.parseDimension(config['width'], 0); + this.width = Phaser.Utils.parseDimension(config['width'], 0); } if (config['height']) { - this.height = this.parseDimension(config['height'], 1); + this.height = Phaser.Utils.parseDimension(config['height'], 1); } if (config['renderer']) @@ -373,46 +366,6 @@ Phaser.Game.prototype = { }, - /** - * Get dimension. - * - * @method Phaser.Game#parseDimension - * @protected - */ - parseDimension: function (size, dimension) { - - var f = 0; - var px = 0; - - if (typeof size === 'string') - { - // %? - if (size.substr(-1) === '%') - { - f = parseInt(size, 10) / 100; - - if (dimension === 0) - { - px = window.innerWidth * f; - } - else - { - px = window.innerHeight * f; - } - } - else - { - px = parseInt(size, 10); - } - } - else - { - px = size; - } - - return px; - - }, /** * Initialize engine sub modules and start the game. @@ -472,12 +425,9 @@ Phaser.Game.prototype = { this.sound.boot(); this.state.boot(); - this.load.onLoadComplete.add(this.loadComplete, this); - this.showDebugHeader(); this.isRunning = true; - this._loadComplete = false; if (this.config && this.config['forceSetTimeOut']) { @@ -589,20 +539,6 @@ Phaser.Game.prototype = { }, - /** - * Called when the load has finished, after preload was run. - * - * @method Phaser.Game#loadComplete - * @protected - */ - loadComplete: function () { - - this._loadComplete = true; - - this.state.loadComplete(); - - }, - /** * The core game loop. * diff --git a/src/core/StateManager.js b/src/core/StateManager.js index a67c0963..081e5dcd 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -121,7 +121,6 @@ Phaser.StateManager = function (game, pendingState) { */ this.onShutDownCallback = null; - }; Phaser.StateManager.prototype = { @@ -135,6 +134,7 @@ Phaser.StateManager.prototype = { this.game.onPause.add(this.pause, this); this.game.onResume.add(this.resume, this); + this.game.load.onLoadComplete.add(this.loadComplete, this); if (this._pendingState !== null) { @@ -306,7 +306,8 @@ Phaser.StateManager.prototype = { // Is the loader empty? if (this.game.load.totalQueuedFiles() === 0) { - this.game.loadComplete(); + this.loadComplete(); + // this.game.loadComplete(); } else { @@ -317,7 +318,8 @@ Phaser.StateManager.prototype = { else { // No init? Then there was nothing to load either - this.game.loadComplete(); + this.loadComplete(); + // this.game.loadComplete(); } this._pendingState = null; diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 152ca34b..10980d20 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -12,6 +12,49 @@ */ Phaser.Utils = { + /** + * Get a unit dimension from a string. + * + * @method Phaser.Utils.parseDimension + * @param {string|number} size - The size to parse. + * @param {number} dimension - The window dimension to check. + * @return {number} The parsed dimension. + */ + parseDimension: function (size, dimension) { + + var f = 0; + var px = 0; + + if (typeof size === 'string') + { + // %? + if (size.substr(-1) === '%') + { + f = parseInt(size, 10) / 100; + + if (dimension === 0) + { + px = window.innerWidth * f; + } + else + { + px = window.innerHeight * f; + } + } + else + { + px = parseInt(size, 10); + } + } + else + { + px = size; + } + + return px; + + }, + /** * A standard Fisher-Yates Array shuffle implementation. * @method Phaser.Utils.shuffle