From a486bf6b4a4f91e9de63214ae06a238fc7b31058 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 10 Sep 2013 16:46:39 +0100 Subject: [PATCH] Phaser now running on iOS. Also fixed a legacy bug where a pending sound wouldn't play once it was touch unlocked. Also fixed Input not working on WebGL contexts. Added WebGL texture updates to the Group/World swap functions. --- examples/input1.php | 7 ++ examples/input2.php | 60 ++++++++++++ examples/sound1.php | 6 +- src/core/Game.js | 4 +- src/core/Group.js | 30 ++++++ src/core/Stage.js | 42 +++++---- src/core/World.js | 30 ++++++ src/input/MSPointer.js | 10 +- src/input/Mouse.js | 7 +- src/input/Pointer.js | 2 - src/input/Touch.js | 12 +-- src/loader/Cache.js | 6 +- src/sound/Sound.js | 88 ++++++++---------- src/sound/SoundManager.js | 174 ++++++++++++++++++----------------- src/system/Canvas.js | 1 + src/system/StageScaleMode.js | 57 +++++++----- src/utils/Debug.js | 3 +- 17 files changed, 338 insertions(+), 201 deletions(-) create mode 100644 examples/input2.php diff --git a/examples/input1.php b/examples/input1.php index b27fa722..fc892ea6 100644 --- a/examples/input1.php +++ b/examples/input1.php @@ -8,6 +8,11 @@ + + + +
+ + + + \ No newline at end of file diff --git a/examples/sound1.php b/examples/sound1.php index 794a9d5d..4e8a60d6 100644 --- a/examples/sound1.php +++ b/examples/sound1.php @@ -26,7 +26,7 @@ function create() { - game.world._stage.backgroundColorString = '#182d3b'; + game.stage.backgroundColor = '#182d3b'; music = game.add.audio('boden'); music.play(); @@ -37,15 +37,11 @@ } function update() { - s.rotation += 0.01; - } function render() { - game.debug.renderSoundInfo(music, 20, 32); - } })(); diff --git a/src/core/Game.js b/src/core/Game.js index 5c563a6a..f2222575 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -312,9 +312,11 @@ Phaser.Game.prototype = { this.load.onLoadComplete.add(this.loadComplete, this); + this.stage.boot(); this.world.boot(); this.state.boot(); this.input.boot(); + this.sound.boot(); if (this.renderType == Phaser.CANVAS) { @@ -355,7 +357,7 @@ Phaser.Game.prototype = { else { // They must have requested WebGL and their browser supports it - this.renderer = new PIXI.WebGLRenderer(this.width, this.height, null, this.transparent, this.antialias); + this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias); this.canvas = this.renderer.view; this.context = null; } diff --git a/src/core/Group.js b/src/core/Group.js index 5e35f821..652dfa16 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -132,6 +132,16 @@ Phaser.Group.prototype = { if (child1Prev) { child1Prev._iNext = child2; } if (child2Next) { child2Next._iPrev = child1; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } else if (child2._iNext == child1) @@ -145,6 +155,16 @@ Phaser.Group.prototype = { if (child2Prev) { child2Prev._iNext = child1; } if (child1Next) { child2Next._iPrev = child2; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } else @@ -160,6 +180,16 @@ Phaser.Group.prototype = { if (child2Prev) { child2Prev._iNext = child1; } if (child2Next) { child2Next._iPrev = child1; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } diff --git a/src/core/Stage.js b/src/core/Stage.js index fed5db15..d80bc0a9 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -27,29 +27,11 @@ Phaser.Stage = function (game, width, height) { // The Pixi Stage which is hooked to the renderer this._stage = new PIXI.Stage(0x000000, false); this._stage.name = '_stage_root'; - - Phaser.Canvas.getOffset(this.canvas, this.offset); - - this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height); - + this.scaleMode = Phaser.StageScaleMode.NO_SCALE; this.scale = new Phaser.StageScaleMode(this.game, width, height); this.aspectRatio = width / height; - var _this = this; - - this._onChange = function (event) { - return _this.visibilityChange(event); - } - - document.addEventListener('visibilitychange', this._onChange, false); - document.addEventListener('webkitvisibilitychange', this._onChange, false); - document.addEventListener('pagehide', this._onChange, false); - document.addEventListener('pageshow', this._onChange, false); - - window.onblur = this._onChange; - window.onfocus = this._onChange; - }; Phaser.Stage.prototype = { @@ -60,6 +42,28 @@ Phaser.Stage.prototype = { bounds: null, offset: null, + boot: function () { + + Phaser.Canvas.getOffset(this.canvas, this.offset); + + this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height); + + var _this = this; + + this._onChange = function (event) { + return _this.visibilityChange(event); + } + + document.addEventListener('visibilitychange', this._onChange, false); + document.addEventListener('webkitvisibilitychange', this._onChange, false); + document.addEventListener('pagehide', this._onChange, false); + document.addEventListener('pageshow', this._onChange, false); + + window.onblur = this._onChange; + window.onfocus = this._onChange; + + }, + /** * This method is called when the document visibility is changed. */ diff --git a/src/core/World.js b/src/core/World.js index 3ffd97cc..94ddbe53 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -148,6 +148,16 @@ Phaser.World.prototype = { if (child1Prev) { child1Prev._iNext = child2; } if (child2Next) { child2Next._iPrev = child1; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } else if (child2._iNext == child1) @@ -161,6 +171,16 @@ Phaser.World.prototype = { if (child2Prev) { child2Prev._iNext = child1; } if (child1Next) { child2Next._iPrev = child2; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } else @@ -176,6 +196,16 @@ Phaser.World.prototype = { if (child2Prev) { child2Prev._iNext = child1; } if (child2Next) { child2Next._iPrev = child1; } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } + + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } + return true; } diff --git a/src/input/MSPointer.js b/src/input/MSPointer.js index 3b0ce222..d6ffa313 100644 --- a/src/input/MSPointer.js +++ b/src/input/MSPointer.js @@ -52,12 +52,12 @@ Phaser.MSPointer.prototype = { return _this.onPointerUp(event); }; - this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false); - this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false); - this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false); + this.game.renderer.view.addEventListener('MSPointerDown', this._onMSPointerDown, false); + this.game.renderer.view.addEventListener('MSPointerMove', this._onMSPointerMove, false); + this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, false); - this.game.stage.canvas.style['-ms-content-zooming'] = 'none'; - this.game.stage.canvas.style['-ms-touch-action'] = 'none'; + this.game.renderer.view.style['-ms-content-zooming'] = 'none'; + this.game.renderer.view.style['-ms-touch-action'] = 'none'; } diff --git a/src/input/Mouse.js b/src/input/Mouse.js index 30797375..2c762435 100644 --- a/src/input/Mouse.js +++ b/src/input/Mouse.js @@ -55,9 +55,10 @@ Phaser.Mouse.prototype = { return _this.onMouseUp(event); }; - this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true); - this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true); - this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true); + this.game.renderer.view.addEventListener('mousedown', this._onMouseDown, true); + this.game.renderer.view.addEventListener('mousemove', this._onMouseMove, true); + this.game.renderer.view.addEventListener('mouseup', this._onMouseUp, true); + }, /** diff --git a/src/input/Pointer.js b/src/input/Pointer.js index a8dea7ca..020a3f20 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -242,8 +242,6 @@ Phaser.Pointer.prototype = { { this.game.input.x = this.x * this.game.input.scale.x; this.game.input.y = this.y * this.game.input.scale.y; - // this.game.input.x = this.x; - // this.game.input.y = this.y; this.game.input.position.setTo(this.x, this.y); this.game.input.onDown.dispatch(this); this.game.input.resetSpeed(this.x, this.y); diff --git a/src/input/Touch.js b/src/input/Touch.js index 31d336c2..91e81dba 100644 --- a/src/input/Touch.js +++ b/src/input/Touch.js @@ -77,12 +77,12 @@ Phaser.Touch.prototype = { return _this.consumeTouchMove(event); }; - this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false); - this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false); - this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false); - this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false); - this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false); - this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false); + this.game.renderer.view.addEventListener('touchstart', this._onTouchStart, false); + this.game.renderer.view.addEventListener('touchmove', this._onTouchMove, false); + this.game.renderer.view.addEventListener('touchend', this._onTouchEnd, false); + this.game.renderer.view.addEventListener('touchenter', this._onTouchEnter, false); + this.game.renderer.view.addEventListener('touchleave', this._onTouchLeave, false); + this.game.renderer.view.addEventListener('touchcancel', this._onTouchCancel, false); document.addEventListener('touchmove', this._documentTouchMove, false); } diff --git a/src/loader/Cache.js b/src/loader/Cache.js index d883b43a..e6f1681b 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -167,7 +167,7 @@ Phaser.Cache.prototype = { decoded = true; } - this._sounds[key] = { url: url, data: data, locked: locked, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag }; + this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag }; }, @@ -354,7 +354,9 @@ Phaser.Cache.prototype = { * @return {object} The sound data you want. */ isSoundReady: function (key) { - return (this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false); + + return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked == false); + }, /** diff --git a/src/sound/Sound.js b/src/sound/Sound.js index 3d1cf13e..da16a432 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -3,6 +3,42 @@ Phaser.Sound = function (game, key, volume, loop) { volume = volume || 1; loop = loop || false; + /** + * Reference to AudioContext instance. + */ + this.context = null; + + /** + * Decoded data buffer / Audio tag. + */ + this._buffer = null; + + this._muted = false; + + this.name = ''; + this.markers = {}; + + this.autoplay = false; + this.totalDuration = 0; + this.startTime = 0; + this.currentTime = 0; + this.duration = 0; + this.stopTime = 0; + this.paused = false; + this.isPlaying = false; + this.currentMarker = ''; + this.pendingPlayback = false; + this.override = false; + + this.onDecoded = null; + this.onPlay = null; + this.onPause = null; + this.onResume = null; + this.onLoop = null; + this.onStop = null; + this.onMute = null; + this.onMarkerComplete = null; + this.game = game; this.key = key; this._volume = volume; @@ -54,55 +90,13 @@ Phaser.Sound = function (game, key, volume, loop) { Phaser.Sound.prototype = { - game: null, - - /** - * Reference to AudioContext instance. - */ - context: null, - - /** - * Decoded data buffer / Audio tag. - */ - _buffer: null, - - _muted: false, - - key: '', - name: '', - markers: {}, - - usingWebAudio: false, - usingAudioTag: false, - autoplay: false, - totalDuration: 0, - startTime: 0, - currentTime: 0, - duration: 0, - stopTime: 0, - paused: false, - loop: false, - isPlaying: false, - currentMarker: '', - pendingPlayback: false, - override: false, - - onDecoded: null, - onPlay: null, - onPause: null, - onResume: null, - onLoop: null, - onStop: null, - onMute: null, - onMarkerComplete: null, - soundHasUnlocked: function (key) { if (key == this.key) { this._sound = this.game.cache.getSoundData(this.key); this.totalDuration = this._sound.duration; - console.log('sound has unlocked', this._sound); + // console.log('sound has unlocked' + this._sound); } }, @@ -201,7 +195,7 @@ Phaser.Sound.prototype = { loop = loop || false; forceRestart = forceRestart || false; - console.log('play', marker, 'current is', this.currentMarker); + // console.log('play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop); if (this.isPlaying == true && forceRestart == false && this.override == false) { @@ -211,7 +205,7 @@ Phaser.Sound.prototype = { if (this.isPlaying && this.override) { - //console.log('asked to play', marker, 'but already playing', this.currentMarker); + // console.log('asked to play ' + marker + ' but already playing ' + this.currentMarker); if (this.usingWebAudio) { @@ -240,7 +234,7 @@ Phaser.Sound.prototype = { this.loop = this.markers[marker].loop; this.duration = this.markers[marker].duration * 1000; - //console.log('marker info loaded', this.loop, this.duration); + // console.log('marker info loaded', this.loop, this.duration); this._tempMarker = marker; this._tempPosition = this.position; this._tempVolume = this.volume; @@ -301,8 +295,6 @@ Phaser.Sound.prototype = { this.currentTime = 0; this.stopTime = this.startTime + this.duration; this.onPlay.dispatch(this); - - //console.log('playing, start', this.startTime, 'stop'); } else { diff --git a/src/sound/SoundManager.js b/src/sound/SoundManager.js index ed21d3b3..814ec2ce 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -7,79 +7,6 @@ Phaser.SoundManager = function (game) { this.game = game; this.onSoundDecode = new Phaser.Signal; - - if (this.game.device.iOS && this.game.device.webAudio == false) - { - this.channels = 1; - } - - if (game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) - { - this.game.input.touch.callbackContext = this; - this.game.input.touch.touchStartCallback = this.unlock; - this.game.input.mouse.callbackContext = this; - this.game.input.mouse.mouseDownCallback = this.unlock; - this.touchLocked = true; - } - else - { - // What about iOS5? - this.touchLocked = false; - } - - if (window['PhaserGlobal']) - { - // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class) - if (window['PhaserGlobal'].disableAudio == true) - { - this.usingWebAudio = false; - this.noAudio = true; - return; - } - - // Check if the Web Audio API is disabled (for testing Audio Tag playback during development) - if (window['PhaserGlobal'].disableWebAudio == true) - { - this.usingWebAudio = false; - this.usingAudioTag = true; - this.noAudio = false; - return; - } - } - - if (!!window['AudioContext']) - { - this.context = new window['AudioContext'](); - } - else if(!!window['webkitAudioContext']) - { - this.context = new window['webkitAudioContext'](); - } - else if(!!window['Audio']) - { - this.usingWebAudio = false; - this.usingAudioTag = true; - } - else - { - this.usingWebAudio = false; - this.noAudio = true; - } - - if (this.context !== null) - { - if (typeof this.context.createGain === 'undefined') - { - this.masterGain = this.context.createGainNode(); - } - else - { - this.masterGain = this.context.createGain(); - } - - this.masterGain.gain.value = 1; - this.masterGain.connect(this.context.destination); - } }; @@ -103,6 +30,84 @@ Phaser.SoundManager.prototype = { channels: 32, + boot: function () { + + if (this.game.device.iOS && this.game.device.webAudio == false) + { + this.channels = 1; + } + + if (this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) + { + this.game.input.touch.callbackContext = this; + this.game.input.touch.touchStartCallback = this.unlock; + this.game.input.mouse.callbackContext = this; + this.game.input.mouse.mouseDownCallback = this.unlock; + this.touchLocked = true; + } + else + { + // What about iOS5? + this.touchLocked = false; + } + + if (window['PhaserGlobal']) + { + // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class) + if (window['PhaserGlobal'].disableAudio == true) + { + this.usingWebAudio = false; + this.noAudio = true; + return; + } + + // Check if the Web Audio API is disabled (for testing Audio Tag playback during development) + if (window['PhaserGlobal'].disableWebAudio == true) + { + this.usingWebAudio = false; + this.usingAudioTag = true; + this.noAudio = false; + return; + } + } + + if (!!window['AudioContext']) + { + this.context = new window['AudioContext'](); + } + else if(!!window['webkitAudioContext']) + { + this.context = new window['webkitAudioContext'](); + } + else if(!!window['Audio']) + { + this.usingWebAudio = false; + this.usingAudioTag = true; + } + else + { + this.usingWebAudio = false; + this.noAudio = true; + } + + if (this.context !== null) + { + if (typeof this.context.createGain === 'undefined') + { + this.masterGain = this.context.createGainNode(); + } + else + { + this.masterGain = this.context.createGain(); + } + + this.masterGain.gain.value = 1; + this.masterGain.connect(this.context.destination); + } + + + }, + unlock: function () { if (this.touchLocked == false) @@ -110,18 +115,8 @@ Phaser.SoundManager.prototype = { return; } - console.log('SoundManager touch unlocked'); - - if (this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) - { - // Create empty buffer and play it - var buffer = this.context.createBuffer(1, 1, 22050); - this._unlockSource = this.context.createBufferSource(); - this._unlockSource.buffer = buffer; - this._unlockSource.connect(this.context.destination); - this._unlockSource.noteOn(0); - } - else + // Global override (mostly for Audio Tag testing) + if (this.game.device.webAudio == false || (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == true)) { // Create an Audio tag? this.touchLocked = false; @@ -131,6 +126,15 @@ Phaser.SoundManager.prototype = { this.game.input.mouse.callbackContext = null; this.game.input.mouse.mouseDownCallback = null; } + else + { + // Create empty buffer and play it + var buffer = this.context.createBuffer(1, 1, 22050); + this._unlockSource = this.context.createBufferSource(); + this._unlockSource.buffer = buffer; + this._unlockSource.connect(this.context.destination); + this._unlockSource.noteOn(0); + } }, diff --git a/src/system/Canvas.js b/src/system/Canvas.js index 25b9b1e0..3fce6ffd 100644 --- a/src/system/Canvas.js +++ b/src/system/Canvas.js @@ -15,6 +15,7 @@ Phaser.Canvas = { var canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; + canvas.style.display = 'block'; return canvas; diff --git a/src/system/StageScaleMode.js b/src/system/StageScaleMode.js index 2f7ce826..92f23814 100644 --- a/src/system/StageScaleMode.js +++ b/src/system/StageScaleMode.js @@ -106,10 +106,6 @@ Phaser.StageScaleMode = function (game, width, height) { this.scaleFactor = new Phaser.Point(1, 1); this.aspectRatio = 0; - this.minWidth = width; - this.minHeight = height; - this.maxWidth = width; - this.maxHeight = height; var _this = this; @@ -136,7 +132,7 @@ Phaser.StageScaleMode.prototype = { return; } - var element = this.game.stage.canvas; + var element = this.game.canvas; if (element['requestFullScreen']) { @@ -286,7 +282,10 @@ Phaser.StageScaleMode.prototype = { */ setScreenSize: function (force) { - force = force || false; + if (typeof force == 'undefined') + { + force = false; + } if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) { @@ -307,7 +306,8 @@ Phaser.StageScaleMode.prototype = { // Set minimum height of content to new window height document.documentElement['style'].minHeight = window.innerHeight + 'px'; - if (this.incorrectOrientation == true) { + if (this.incorrectOrientation == true) + { this.setMaximum(); } else if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT) @@ -351,20 +351,20 @@ Phaser.StageScaleMode.prototype = { } } - this.game.stage.canvas.style.width = this.width + 'px'; - this.game.stage.canvas.style.height = this.height + 'px'; + this.game.canvas.style.width = this.width + 'px'; + this.game.canvas.style.height = this.height + 'px'; - this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height); + this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height); if (this.pageAlignHorizontally) { if (this.width < window.innerWidth && this.incorrectOrientation == false) { - this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px'; + this.game.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px'; } else { - this.game.stage.canvas.style.marginLeft = '0px'; + this.game.canvas.style.marginLeft = '0px'; } } @@ -372,19 +372,21 @@ Phaser.StageScaleMode.prototype = { { if (this.height < window.innerHeight && this.incorrectOrientation == false) { - this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px'; + this.game.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px'; } else { - this.game.stage.canvas.style.marginTop = '0px'; + this.game.canvas.style.marginTop = '0px'; } } - this.game.stage.getOffset(this.game.stage.canvas); + Phaser.Canvas.getOffset(this.game.canvas, this.game.stage.offset); + this.aspectRatio = this.width / this.height; - this.scaleFactor.x = this.game.stage.width / this.width; - this.scaleFactor.y = this.game.stage.height / this.height; + this.scaleFactor.x = this.game.width / this.width; + this.scaleFactor.y = this.game.height / this.height; + }, setMaximum: function () { @@ -396,33 +398,40 @@ Phaser.StageScaleMode.prototype = { setShowAll: function () { - var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width)); + var multiplier = Math.min((window.innerHeight / this.game.height), (window.innerWidth / this.game.width)); - this.width = Math.round(this.game.stage.width * multiplier); - this.height = Math.round(this.game.stage.height * multiplier); + this.width = Math.round(this.game.width * multiplier); + this.height = Math.round(this.game.height * multiplier); }, setExactFit: function () { - if (this.maxWidth && window.innerWidth > this.maxWidth) + var availableWidth = window.innerWidth - 0; + var availableHeight = window.innerHeight - 5; + + console.log('available', availableWidth, availableHeight); + + if (this.maxWidth && availableWidth > this.maxWidth) { this.width = this.maxWidth; } else { - this.width = window.innerWidth; + this.width = availableWidth; } - if (this.maxHeight && window.innerHeight > this.maxHeight) + if (this.maxHeight && availableHeight > this.maxHeight) { this.height = this.maxHeight; } else { - this.height = window.innerHeight; + this.height = availableHeight; } + console.log('setExactFit', this.width, this.height, this.game.stage.offset); + } }; diff --git a/src/utils/Debug.js b/src/utils/Debug.js index 146a4cec..5444606f 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -196,7 +196,8 @@ Phaser.Utils.Debug.prototype = { color = color || 'rgb(255,255,255)'; this.start(x, y, color); - this.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback); + this.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked); + this.line('Is Ready?: ' + this.game.cache.isSoundReady(sound.key) + ' Pending Playback: ' + sound.pendingPlayback); this.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding); this.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying); this.line('Time: ' + sound.currentTime);