Fixed Fullscreen example and State preloading.

This commit is contained in:
photonstorm 2014-02-25 16:26:11 +00:00
parent 1646157c0c
commit be27442139
5 changed files with 104 additions and 82 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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.
*

View file

@ -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;

View file

@ -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