Multiple fixes to remove the use of reserved words, making the YUI compressor work again.

This commit is contained in:
Richard Davey 2013-07-19 02:59:23 +01:00
parent a2c756e37f
commit 9827e7522f
12 changed files with 356 additions and 164 deletions

View file

@ -183,8 +183,16 @@ module Phaser {
if (this.clear)
{
// implement dirty rect? could take up more cpu time than it saves. needs benching.
this.context.clearRect(0, 0, this.width, this.height);
// A 'fix' for the horrendous Android stock browser bug: https://code.google.com/p/android/issues/detail?id=39247
if (this._game.device.android && this._game.device.chrome == false)
{
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillRect(0, 0, this.width, this.height);
}
else
{
this.context.clearRect(0, 0, this.width, this.height);
}
}
if (this._game.paused && this.scale.incorrectOrientation)
@ -215,25 +223,17 @@ module Phaser {
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
{
if (this._game.paused == false && this.disablePauseScreen == false)
if (this._game.paused == false)
{
this.pauseGame();
}
else
{
this._game.paused = true;
}
}
else
{
if (this._game.paused == true && this.disablePauseScreen == false)
if (this._game.paused == true)
{
this.resumeGame();
}
else
{
this._game.paused = false;
}
}
}

View file

@ -27,8 +27,8 @@ module Phaser {
this._cameras = [];
this.default = this.addCamera(x, y, width, height);
this.current = this.default;
this.defaultCamera = this.addCamera(x, y, width, height);
this.current = this.defaultCamera;
}
@ -68,7 +68,7 @@ module Phaser {
/**
* The default created camera.
*/
public default: Camera;
public defaultCamera: Camera;
/**
* Get all the cameras.

View file

@ -186,6 +186,27 @@ module Phaser {
*/
public tileSpacing: number = 0;
/**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile in world coordinates.
* @param y {number} Y position of this tile in world coordinates.
* @param index {number} The index of this tile type in the core map data.
*/
public putTileWorldXY(x: number, y: number, index: number) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if (y >= 0 && y < this.mapData.length)
{
if (x >= 0 && x < this.mapData[y].length)
{
this.mapData[y][x] = index;
}
}
}
/**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile.
@ -194,9 +215,6 @@ module Phaser {
*/
public putTile(x: number, y: number, index: number) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if (y >= 0 && y < this.mapData.length)
{
if (x >= 0 && x < this.mapData[y].length)

View file

@ -124,8 +124,6 @@ module Phaser {
*/
public addSound(key: string, url: string, data, webAudio: bool = true, audioTag: bool = false) {
console.log('Cache addSound: ' + key + ' url: ' + url, webAudio, audioTag);
var locked: bool = this._game.sound.touchLocked;
var decoded: bool = false;
@ -139,8 +137,6 @@ module Phaser {
public reloadSound(key: string) {
console.log('reloadSound', key);
if (this._sounds[key])
{
this._sounds[key].data.src = this._sounds[key].url;
@ -154,8 +150,6 @@ module Phaser {
public reloadSoundComplete(key: string) {
console.log('reloadSoundComplete', key);
if (this._sounds[key])
{
this._sounds[key].locked = false;
@ -180,7 +174,6 @@ module Phaser {
*/
public decodedSound(key: string, data) {
console.log('decoded sound', key);
this._sounds[key].data = data;
this._sounds[key].decoded = true;
this._sounds[key].isDecoding = false;

View file

@ -330,8 +330,8 @@ module Phaser {
case 'audio':
file.url = this.getAudioURL(file.url);
console.log('Loader audio');
console.log(file.url);
//console.log('Loader audio');
//console.log(file.url);
if (file.url !== null)
{
@ -349,7 +349,7 @@ module Phaser {
if (this._game.sound.touchLocked)
{
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
console.log('Audio is touch locked');
//console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
@ -358,7 +358,6 @@ module Phaser {
}
else
{
console.log('Audio not touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.onerror = () => this.fileError(file.key);
@ -394,8 +393,8 @@ module Phaser {
if (this._game.device.canPlayAudio(extension))
{
console.log('getAudioURL', urls[i]);
console.log(urls[i]);
//console.log('getAudioURL', urls[i]);
//console.log(urls[i]);
return urls[i];
}

View file

@ -43,7 +43,7 @@ module Phaser {
}
else
{
if (this.game.cache.getSound(key).locked == false)
if (this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false)
{
this._sound = this.game.cache.getSoundData(key);
this.totalDuration = this._sound.duration;
@ -65,6 +65,7 @@ module Phaser {
this.onLoop = new Phaser.Signal;
this.onStop = new Phaser.Signal;
this.onMute = new Phaser.Signal;
this.onMarkerComplete = new Phaser.Signal;
}
@ -102,7 +103,7 @@ module Phaser {
/**
* Decoded data buffer / Audio tag.
*/
private _buffer;
private _buffer = null;
/**
* Volume of this sound.
@ -148,6 +149,7 @@ module Phaser {
public onLoop: Phaser.Signal;
public onStop: Phaser.Signal;
public onMute: Phaser.Signal;
public onMarkerComplete: Phaser.Signal;
public pendingPlayback: bool = false;
@ -171,7 +173,6 @@ module Phaser {
if (this.pendingPlayback && this.game.cache.isSoundReady(this.key))
{
console.log('pending over');
this.pendingPlayback = false;
this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
}
@ -182,16 +183,32 @@ module Phaser {
if (this.currentTime >= this.duration)
{
console.log(this.currentMarker, 'has hit duration');
if (this.usingWebAudio)
{
if (this.loop)
{
console.log('loop1');
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
this.currentTime = 0;
this.startTime = this.game.time.now;
if (this.currentMarker == '')
{
console.log('loop2');
this.currentTime = 0;
this.startTime = this.game.time.now;
}
else
{
console.log('loop3');
this.play(this.currentMarker, 0, this.volume, true, true);
}
}
else
{
console.log('stopping, no loop for marker');
this.stop();
}
}
@ -213,6 +230,8 @@ module Phaser {
}
public override: bool = false;
/**
* Play this sound, or a marked section of it.
* @param marker {string} Assets key of the sound you want to play.
@ -222,12 +241,35 @@ module Phaser {
*/
public play(marker: string = '', position?: number = 0, volume?: number = 1, loop?: bool = false, forceRestart: bool = false) {
if (this.isPlaying == true && forceRestart == false)
console.log('play', marker, 'current is', this.currentMarker);
if (this.isPlaying == true && forceRestart == false && this.override == false)
{
// Use Restart instead
return;
}
if (this.isPlaying && this.override)
{
console.log('asked to play', marker, 'but already playing', this.currentMarker);
if (this.usingWebAudio)
{
if (typeof this._sound.stop === 'undefined')
{
this._sound.noteOff(0);
}
else
{
this._sound.stop(0);
}
}
else if (this.usingAudioTag)
{
this._sound.pause();
this._sound.currentTime = 0;
}
}
this.currentMarker = marker;
if (marker !== '' && this.markers[marker])
@ -236,6 +278,13 @@ module Phaser {
this.volume = this.markers[marker].volume;
this.loop = this.markers[marker].loop;
this.duration = this.markers[marker].duration * 1000;
console.log('marker info loaded', this.loop, this.duration);
this._tempMarker = marker;
this._tempPosition = this.position;
this._tempVolume = this.volume;
this._tempLoop = this.loop;
}
else
{
@ -243,12 +292,12 @@ module Phaser {
this.volume = volume;
this.loop = loop;
this.duration = 0;
}
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
}
if (this.usingWebAudio)
{
@ -256,18 +305,25 @@ module Phaser {
if (this.game.cache.isSoundDecoded(this.key))
{
// Do we need to do this every time we play? How about just if the buffer is empty?
this._buffer = this.game.cache.getSoundData(this.key);
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration;
if (this._buffer == null)
{
this._buffer = this.game.cache.getSoundData(this.key);
}
//if (this._sound == null)
//{
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration;
//}
if (this.duration == 0)
{
this.duration = this.totalDuration * 1000;
}
if (this.loop)
if (this.loop && marker == '')
{
this._sound.loop = true;
}
@ -288,12 +344,15 @@ module Phaser {
this.currentTime = 0;
this.stopTime = this.startTime + this.duration;
this.onPlay.dispatch(this);
console.log('playing, start', this.startTime, 'stop');
}
else
{
this.pendingPlayback = true;
if (this.game.cache.getSound(this.key).isDecoding == false)
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false)
{
this.game.sound.decode(this.key, this);
}
@ -301,17 +360,17 @@ module Phaser {
}
else
{
console.log('Sound play Audio');
//console.log('Sound play Audio');
if (this.game.cache.getSound(this.key).locked)
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked)
{
console.log('tried playing locked sound, pending set, reload started');
//console.log('tried playing locked sound, pending set, reload started');
this.game.cache.reloadSound(this.key);
this.pendingPlayback = true;
}
else
{
console.log('sound not locked, state?', this._sound.readyState);
//console.log('sound not locked, state?', this._sound.readyState);
if (this._sound && this._sound.readyState == 4)
{
if (this.duration == 0)
@ -319,10 +378,19 @@ module Phaser {
this.duration = this.totalDuration * 1000;
}
console.log('playing', this._sound);
//console.log('playing', this._sound);
this._sound.currentTime = this.position;
this._sound.muted = this._muted;
this._sound.volume = this._volume;
if (this._muted)
{
this._sound.volume = 0;
}
else
{
this._sound.volume = this._volume;
}
this._sound.play();
this.isPlaying = true;
@ -391,6 +459,8 @@ module Phaser {
*/
public stop() {
console.log('Sound.stop', this.currentMarker);
if (this.isPlaying && this._sound)
{
if (this.usingWebAudio)
@ -405,17 +475,20 @@ module Phaser {
}
}
else if (this.usingAudioTag)
{
{
this._sound.pause();
this._sound.currentTime = 0;
}
this.isPlaying = false;
this.currentMarker = '';
this.onStop.dispatch(this);
}
this.isPlaying = false;
var prevMarker:string = this.currentMarker;
this.currentMarker = '';
this.onStop.dispatch(this, prevMarker);
}
/**

View file

@ -30,7 +30,7 @@ module Phaser {
if (this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock))
{
console.log('iOS Touch Locked');
//console.log('iOS Touch Locked');
this.game.input.touch.callbackContext = this;
this.game.input.touch.touchStartCallback = this.unlock;
this.game.input.mouse.callbackContext = this;
@ -146,11 +146,11 @@ module Phaser {
return;
}
console.log('SoundManager touch unlocked');
//console.log('SoundManager touch unlocked');
if (this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false))
{
console.log('create empty buffer');
//console.log('create empty buffer');
// Create empty buffer and play it
var buffer = this.context.createBuffer(1, 1, 22050);
this._unlockSource = this.context.createBufferSource();
@ -161,7 +161,7 @@ module Phaser {
else
{
// Create an Audio tag?
console.log('create audio tag');
//console.log('create audio tag');
this.touchLocked = false;
this._unlockSource = null;
this.game.input.touch.callbackContext = null;
@ -181,6 +181,8 @@ module Phaser {
public set mute(value: bool) {
console.log('SoundManager mute', value);
if (value)
{
if (this._muted)
@ -199,7 +201,7 @@ module Phaser {
// Loop through sounds
for (var i = 0; i < this._sounds.length; i++)
{
if (this._sounds[i])
if (this._sounds[i].usingAudioTag)
{
this._sounds[i].mute = true;
}
@ -222,7 +224,7 @@ module Phaser {
// Loop through sounds
for (var i = 0; i < this._sounds.length; i++)
{
if (this._sounds[i])
if (this._sounds[i].usingAudioTag)
{
this._sounds[i].mute = false;
}

View file

@ -159,6 +159,12 @@ module Phaser {
*/
public aspectRatio: number;
/**
* The maximum number of times it will try to resize the canvas to fill the browser (default is 10)
* @type {number}
*/
public maxIterations: number = 10;
/**
* The scale factor of the scaled game width
* @type {Vec2}
@ -348,7 +354,7 @@ module Phaser {
// We can't do anything about the status bars in iPads, web apps or desktops
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
{
document.documentElement.style.minHeight = '5000px';
document.documentElement.style.minHeight = '2000px';
this._startHeight = window.innerHeight;
@ -362,9 +368,9 @@ module Phaser {
}
}
if (this._check == null)
if (this._check == null && this.maxIterations > 0)
{
this._iterations = 40;
this._iterations = this.maxIterations;
this._check = window.setInterval(() => this.setScreenSize(), 10);
this.setScreenSize();
}

View file

@ -61,9 +61,6 @@ TODO:
* When you toggle visible of a button that is over, it doesn't disable that 'over' state (should it? probably yes)
* Stage.opaqueBackground = 'rgb()' or null, alpha, blendMode, filters, mask, rotation+XYZ,scaleXYZ,visible
* Need a way for Input event to redirect to audio to unlock playback
* AudioSprite object?
* How to get web audio to playback from an offset
* Stage lost to mute
@ -158,6 +155,9 @@ V1.0.0
* Updated Loader and Cache so they now support loading of Audio() tags as well as Web Audio.
* Set Input.recordPointerHistory to false, you now need to enable the pointer tracking if you wish to use it.
* SoundManager will now automatically handle iOS touch unlocking.
* Added TilemapLayer.putTileWorldXY to place a tile based on pixel values, and putTile based on tile map coordinates.
* Dropped the StageScaleMode.setScreenSize iterations count from 40 down to 10 and document min body height to 2000px.

View file

@ -9238,8 +9238,8 @@ var Phaser;
break;
case 'audio':
file.url = this.getAudioURL(file.url);
console.log('Loader audio');
console.log(file.url);
//console.log('Loader audio');
//console.log(file.url);
if(file.url !== null) {
// WebAudio or Audio Tag?
if(this._game.sound.usingWebAudio) {
@ -9255,14 +9255,13 @@ var Phaser;
} else if(this._game.sound.usingAudioTag) {
if(this._game.sound.touchLocked) {
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
console.log('Audio is touch locked');
//console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
file.data.src = file.url;
this.fileComplete(file.key);
} else {
console.log('Audio not touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.onerror = function () {
@ -9297,8 +9296,8 @@ var Phaser;
extension = urls[i].toLowerCase();
extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
if(this._game.device.canPlayAudio(extension)) {
console.log('getAudioURL', urls[i]);
console.log(urls[i]);
//console.log('getAudioURL', urls[i]);
//console.log(urls[i]);
return urls[i];
}
}
@ -9557,7 +9556,6 @@ var Phaser;
function (key, url, data, webAudio, audioTag) {
if (typeof webAudio === "undefined") { webAudio = true; }
if (typeof audioTag === "undefined") { audioTag = false; }
console.log('Cache addSound: ' + key + ' url: ' + url, webAudio, audioTag);
var locked = this._game.sound.touchLocked;
var decoded = false;
if(audioTag) {
@ -9575,7 +9573,6 @@ var Phaser;
};
Cache.prototype.reloadSound = function (key) {
var _this = this;
console.log('reloadSound', key);
if(this._sounds[key]) {
this._sounds[key].data.src = this._sounds[key].url;
this._sounds[key].data.addEventListener('canplaythrough', function () {
@ -9585,7 +9582,6 @@ var Phaser;
}
};
Cache.prototype.reloadSoundComplete = function (key) {
console.log('reloadSoundComplete', key);
if(this._sounds[key]) {
this._sounds[key].locked = false;
this.onSoundUnlock.dispatch(key);
@ -9602,7 +9598,6 @@ var Phaser;
* @param data {object} Extra sound data.
*/
function (key, data) {
console.log('decoded sound', key);
this._sounds[key].data = data;
this._sounds[key].decoded = true;
this._sounds[key].isDecoding = false;
@ -11468,8 +11463,8 @@ var Phaser;
this._sortIndex = '';
this._game = game;
this._cameras = [];
this.default = this.addCamera(x, y, width, height);
this.current = this.default;
this.defaultCamera = this.addCamera(x, y, width, height);
this.current = this.defaultCamera;
}
CameraManager.CAMERA_TYPE_ORTHOGRAPHIC = 0;
CameraManager.CAMERA_TYPE_ISOMETRIC = 1;
@ -13088,6 +13083,21 @@ var Phaser;
this.mapData = [];
this._tempTileBlock = [];
}
TilemapLayer.prototype.putTileWorldXY = /**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile in world coordinates.
* @param y {number} Y position of this tile in world coordinates.
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
}
}
};
TilemapLayer.prototype.putTile = /**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile.
@ -13095,8 +13105,6 @@ var Phaser;
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
@ -14120,6 +14128,10 @@ var Phaser;
* Reference to AudioContext instance.
*/
this.context = null;
/**
* Decoded data buffer / Audio tag.
*/
this._buffer = null;
this._muted = false;
this.usingWebAudio = false;
this.usingAudioTag = false;
@ -14135,6 +14147,7 @@ var Phaser;
this.isPlaying = false;
this.currentMarker = '';
this.pendingPlayback = false;
this.override = false;
this.game = game;
this.usingWebAudio = this.game.sound.usingWebAudio;
this.usingAudioTag = this.game.sound.usingAudioTag;
@ -14150,7 +14163,7 @@ var Phaser;
this.gainNode.gain.value = volume * this.game.sound.volume;
this.gainNode.connect(this.masterGainNode);
} else {
if(this.game.cache.getSound(key).locked == false) {
if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
this._sound = this.game.cache.getSoundData(key);
this.totalDuration = this._sound.duration;
} else {
@ -14168,6 +14181,7 @@ var Phaser;
this.onLoop = new Phaser.Signal();
this.onStop = new Phaser.Signal();
this.onMute = new Phaser.Signal();
this.onMarkerComplete = new Phaser.Signal();
}
Sound.prototype.soundHasUnlocked = function (key) {
if(key == this.key) {
@ -14207,19 +14221,28 @@ var Phaser;
};
Sound.prototype.update = function () {
if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
console.log('pending over');
this.pendingPlayback = false;
this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
}
if(this.isPlaying) {
this.currentTime = this.game.time.now - this.startTime;
if(this.currentTime >= this.duration) {
console.log(this.currentMarker, 'has hit duration');
if(this.usingWebAudio) {
if(this.loop) {
console.log('loop1');
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
this.currentTime = 0;
this.startTime = this.game.time.now;
if(this.currentMarker == '') {
console.log('loop2');
this.currentTime = 0;
this.startTime = this.game.time.now;
} else {
console.log('loop3');
this.play(this.currentMarker, 0, this.volume, true, true);
}
} else {
console.log('stopping, no loop for marker');
this.stop();
}
} else {
@ -14246,39 +14269,63 @@ var Phaser;
if (typeof volume === "undefined") { volume = 1; }
if (typeof loop === "undefined") { loop = false; }
if (typeof forceRestart === "undefined") { forceRestart = false; }
if(this.isPlaying == true && forceRestart == false) {
console.log('play', marker, 'current is', this.currentMarker);
if(this.isPlaying == true && forceRestart == false && this.override == false) {
// Use Restart instead
return;
}
if(this.isPlaying && this.override) {
console.log('asked to play', marker, 'but already playing', this.currentMarker);
if(this.usingWebAudio) {
if(typeof this._sound.stop === 'undefined') {
this._sound.noteOff(0);
} else {
this._sound.stop(0);
}
} else if(this.usingAudioTag) {
this._sound.pause();
this._sound.currentTime = 0;
}
}
this.currentMarker = marker;
if(marker !== '' && this.markers[marker]) {
this.position = this.markers[marker].start;
this.volume = this.markers[marker].volume;
this.loop = this.markers[marker].loop;
this.duration = this.markers[marker].duration * 1000;
console.log('marker info loaded', this.loop, this.duration);
this._tempMarker = marker;
this._tempPosition = this.position;
this._tempVolume = this.volume;
this._tempLoop = this.loop;
} else {
this.position = position;
this.volume = volume;
this.loop = loop;
this.duration = 0;
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
}
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
if(this.usingWebAudio) {
// Does the sound need decoding?
if(this.game.cache.isSoundDecoded(this.key)) {
// Do we need to do this every time we play? How about just if the buffer is empty?
this._buffer = this.game.cache.getSoundData(this.key);
if(this._buffer == null) {
this._buffer = this.game.cache.getSoundData(this.key);
}
//if (this._sound == null)
//{
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration;
//}
if(this.duration == 0) {
this.duration = this.totalDuration * 1000;
}
if(this.loop) {
if(this.loop && marker == '') {
this._sound.loop = true;
}
// Useful to cache this somewhere perhaps?
@ -14293,25 +14340,26 @@ var Phaser;
this.currentTime = 0;
this.stopTime = this.startTime + this.duration;
this.onPlay.dispatch(this);
console.log('playing, start', this.startTime, 'stop');
} else {
this.pendingPlayback = true;
if(this.game.cache.getSound(this.key).isDecoding == false) {
if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
this.game.sound.decode(this.key, this);
}
}
} else {
console.log('Sound play Audio');
//console.log('Sound play Audio');
if(this.game.cache.getSound(this.key).locked) {
console.log('tried playing locked sound, pending set, reload started');
//console.log('tried playing locked sound, pending set, reload started');
this.game.cache.reloadSound(this.key);
this.pendingPlayback = true;
} else {
console.log('sound not locked, state?', this._sound.readyState);
//console.log('sound not locked, state?', this._sound.readyState);
if(this._sound && this._sound.readyState == 4) {
if(this.duration == 0) {
this.duration = this.totalDuration * 1000;
}
console.log('playing', this._sound);
//console.log('playing', this._sound);
this._sound.currentTime = this.position;
this._sound.muted = this._muted;
this._sound.volume = this._volume;
@ -14364,6 +14412,7 @@ var Phaser;
* Stop playing this sound.
*/
function () {
console.log('Sound.stop', this.currentMarker);
if(this.isPlaying && this._sound) {
if(this.usingWebAudio) {
if(typeof this._sound.stop === 'undefined') {
@ -14375,10 +14424,11 @@ var Phaser;
this._sound.pause();
this._sound.currentTime = 0;
}
this.isPlaying = false;
this.currentMarker = '';
this.onStop.dispatch(this);
}
this.isPlaying = false;
var prevMarker = this.currentMarker;
this.currentMarker = '';
this.onStop.dispatch(this, prevMarker);
};
Object.defineProperty(Sound.prototype, "mute", {
get: /**
@ -14482,7 +14532,7 @@ var Phaser;
this.channels = 1;
}
if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
console.log('iOS Touch Locked');
//console.log('iOS Touch Locked');
this.game.input.touch.callbackContext = this;
this.game.input.touch.touchStartCallback = this.unlock;
this.game.input.mouse.callbackContext = this;
@ -14534,9 +14584,9 @@ var Phaser;
if(this.touchLocked == false) {
return;
}
console.log('SoundManager touch unlocked');
//console.log('SoundManager touch unlocked');
if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
console.log('create empty buffer');
//console.log('create empty buffer');
// Create empty buffer and play it
var buffer = this.context.createBuffer(1, 1, 22050);
this._unlockSource = this.context.createBufferSource();
@ -14545,7 +14595,7 @@ var Phaser;
this._unlockSource.noteOn(0);
} else {
// Create an Audio tag?
console.log('create audio tag');
//console.log('create audio tag');
this.touchLocked = false;
this._unlockSource = null;
this.game.input.touch.callbackContext = null;
@ -14936,7 +14986,7 @@ var Phaser;
var _this = this;
// We can't do anything about the status bars in iPads, web apps or desktops
if(this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false) {
document.documentElement.style.minHeight = '5000px';
document.documentElement.style.minHeight = '2000px';
this._startHeight = window.innerHeight;
if(this._game.device.android && this._game.device.chrome == false) {
window.scrollTo(0, 1);
@ -14945,7 +14995,7 @@ var Phaser;
}
}
if(this._check == null) {
this._iterations = 40;
this._iterations = 10;
this._check = window.setInterval(function () {
return _this.setScreenSize();
}, 10);
@ -15425,16 +15475,12 @@ var Phaser;
*/
function (event) {
if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
if(this._game.paused == false && this.disablePauseScreen == false) {
if(this._game.paused == false) {
this.pauseGame();
} else {
this._game.paused = true;
}
} else {
if(this._game.paused == true && this.disablePauseScreen == false) {
if(this._game.paused == true) {
this.resumeGame();
} else {
this._game.paused = false;
}
}
};

11
build/phaser.d.ts vendored
View file

@ -5490,7 +5490,7 @@ module Phaser {
/**
* The default created camera.
*/
public default: Camera;
public defaultCamera: Camera;
/**
* Get all the cameras.
*
@ -6336,6 +6336,13 @@ module Phaser {
public tileSpacing: number;
/**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile in world coordinates.
* @param y {number} Y position of this tile in world coordinates.
* @param index {number} The index of this tile type in the core map data.
*/
public putTileWorldXY(x: number, y: number, index: number): void;
/**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile.
* @param y {number} Y position of this tile.
* @param index {number} The index of this tile type in the core map data.
@ -7018,12 +7025,14 @@ module Phaser {
public onLoop: Signal;
public onStop: Signal;
public onMute: Signal;
public onMarkerComplete: Signal;
public pendingPlayback: bool;
public isDecoding : bool;
public isDecoded : bool;
public addMarker(name: string, start: number, stop: number, volume?: number, loop?: bool): void;
public removeMarker(name: string): void;
public update(): void;
public override: bool;
/**
* Play this sound, or a marked section of it.
* @param marker {string} Assets key of the sound you want to play.

View file

@ -9238,8 +9238,8 @@ var Phaser;
break;
case 'audio':
file.url = this.getAudioURL(file.url);
console.log('Loader audio');
console.log(file.url);
//console.log('Loader audio');
//console.log(file.url);
if(file.url !== null) {
// WebAudio or Audio Tag?
if(this._game.sound.usingWebAudio) {
@ -9255,14 +9255,13 @@ var Phaser;
} else if(this._game.sound.usingAudioTag) {
if(this._game.sound.touchLocked) {
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
console.log('Audio is touch locked');
//console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
file.data.src = file.url;
this.fileComplete(file.key);
} else {
console.log('Audio not touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.onerror = function () {
@ -9297,8 +9296,8 @@ var Phaser;
extension = urls[i].toLowerCase();
extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
if(this._game.device.canPlayAudio(extension)) {
console.log('getAudioURL', urls[i]);
console.log(urls[i]);
//console.log('getAudioURL', urls[i]);
//console.log(urls[i]);
return urls[i];
}
}
@ -9557,7 +9556,6 @@ var Phaser;
function (key, url, data, webAudio, audioTag) {
if (typeof webAudio === "undefined") { webAudio = true; }
if (typeof audioTag === "undefined") { audioTag = false; }
console.log('Cache addSound: ' + key + ' url: ' + url, webAudio, audioTag);
var locked = this._game.sound.touchLocked;
var decoded = false;
if(audioTag) {
@ -9575,7 +9573,6 @@ var Phaser;
};
Cache.prototype.reloadSound = function (key) {
var _this = this;
console.log('reloadSound', key);
if(this._sounds[key]) {
this._sounds[key].data.src = this._sounds[key].url;
this._sounds[key].data.addEventListener('canplaythrough', function () {
@ -9585,7 +9582,6 @@ var Phaser;
}
};
Cache.prototype.reloadSoundComplete = function (key) {
console.log('reloadSoundComplete', key);
if(this._sounds[key]) {
this._sounds[key].locked = false;
this.onSoundUnlock.dispatch(key);
@ -9602,7 +9598,6 @@ var Phaser;
* @param data {object} Extra sound data.
*/
function (key, data) {
console.log('decoded sound', key);
this._sounds[key].data = data;
this._sounds[key].decoded = true;
this._sounds[key].isDecoding = false;
@ -11468,8 +11463,8 @@ var Phaser;
this._sortIndex = '';
this._game = game;
this._cameras = [];
this.default = this.addCamera(x, y, width, height);
this.current = this.default;
this.defaultCamera = this.addCamera(x, y, width, height);
this.current = this.defaultCamera;
}
CameraManager.CAMERA_TYPE_ORTHOGRAPHIC = 0;
CameraManager.CAMERA_TYPE_ISOMETRIC = 1;
@ -13088,6 +13083,21 @@ var Phaser;
this.mapData = [];
this._tempTileBlock = [];
}
TilemapLayer.prototype.putTileWorldXY = /**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile in world coordinates.
* @param y {number} Y position of this tile in world coordinates.
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
}
}
};
TilemapLayer.prototype.putTile = /**
* Set a specific tile with its x and y in tiles.
* @param x {number} X position of this tile.
@ -13095,8 +13105,6 @@ var Phaser;
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
@ -14120,6 +14128,10 @@ var Phaser;
* Reference to AudioContext instance.
*/
this.context = null;
/**
* Decoded data buffer / Audio tag.
*/
this._buffer = null;
this._muted = false;
this.usingWebAudio = false;
this.usingAudioTag = false;
@ -14135,6 +14147,7 @@ var Phaser;
this.isPlaying = false;
this.currentMarker = '';
this.pendingPlayback = false;
this.override = false;
this.game = game;
this.usingWebAudio = this.game.sound.usingWebAudio;
this.usingAudioTag = this.game.sound.usingAudioTag;
@ -14150,7 +14163,7 @@ var Phaser;
this.gainNode.gain.value = volume * this.game.sound.volume;
this.gainNode.connect(this.masterGainNode);
} else {
if(this.game.cache.getSound(key).locked == false) {
if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
this._sound = this.game.cache.getSoundData(key);
this.totalDuration = this._sound.duration;
} else {
@ -14168,6 +14181,7 @@ var Phaser;
this.onLoop = new Phaser.Signal();
this.onStop = new Phaser.Signal();
this.onMute = new Phaser.Signal();
this.onMarkerComplete = new Phaser.Signal();
}
Sound.prototype.soundHasUnlocked = function (key) {
if(key == this.key) {
@ -14207,19 +14221,28 @@ var Phaser;
};
Sound.prototype.update = function () {
if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
console.log('pending over');
this.pendingPlayback = false;
this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
}
if(this.isPlaying) {
this.currentTime = this.game.time.now - this.startTime;
if(this.currentTime >= this.duration) {
console.log(this.currentMarker, 'has hit duration');
if(this.usingWebAudio) {
if(this.loop) {
console.log('loop1');
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
this.currentTime = 0;
this.startTime = this.game.time.now;
if(this.currentMarker == '') {
console.log('loop2');
this.currentTime = 0;
this.startTime = this.game.time.now;
} else {
console.log('loop3');
this.play(this.currentMarker, 0, this.volume, true, true);
}
} else {
console.log('stopping, no loop for marker');
this.stop();
}
} else {
@ -14246,39 +14269,63 @@ var Phaser;
if (typeof volume === "undefined") { volume = 1; }
if (typeof loop === "undefined") { loop = false; }
if (typeof forceRestart === "undefined") { forceRestart = false; }
if(this.isPlaying == true && forceRestart == false) {
console.log('play', marker, 'current is', this.currentMarker);
if(this.isPlaying == true && forceRestart == false && this.override == false) {
// Use Restart instead
return;
}
if(this.isPlaying && this.override) {
console.log('asked to play', marker, 'but already playing', this.currentMarker);
if(this.usingWebAudio) {
if(typeof this._sound.stop === 'undefined') {
this._sound.noteOff(0);
} else {
this._sound.stop(0);
}
} else if(this.usingAudioTag) {
this._sound.pause();
this._sound.currentTime = 0;
}
}
this.currentMarker = marker;
if(marker !== '' && this.markers[marker]) {
this.position = this.markers[marker].start;
this.volume = this.markers[marker].volume;
this.loop = this.markers[marker].loop;
this.duration = this.markers[marker].duration * 1000;
console.log('marker info loaded', this.loop, this.duration);
this._tempMarker = marker;
this._tempPosition = this.position;
this._tempVolume = this.volume;
this._tempLoop = this.loop;
} else {
this.position = position;
this.volume = volume;
this.loop = loop;
this.duration = 0;
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
}
this._tempMarker = marker;
this._tempPosition = position;
this._tempVolume = volume;
this._tempLoop = loop;
if(this.usingWebAudio) {
// Does the sound need decoding?
if(this.game.cache.isSoundDecoded(this.key)) {
// Do we need to do this every time we play? How about just if the buffer is empty?
this._buffer = this.game.cache.getSoundData(this.key);
if(this._buffer == null) {
this._buffer = this.game.cache.getSoundData(this.key);
}
//if (this._sound == null)
//{
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration;
//}
if(this.duration == 0) {
this.duration = this.totalDuration * 1000;
}
if(this.loop) {
if(this.loop && marker == '') {
this._sound.loop = true;
}
// Useful to cache this somewhere perhaps?
@ -14293,25 +14340,26 @@ var Phaser;
this.currentTime = 0;
this.stopTime = this.startTime + this.duration;
this.onPlay.dispatch(this);
console.log('playing, start', this.startTime, 'stop');
} else {
this.pendingPlayback = true;
if(this.game.cache.getSound(this.key).isDecoding == false) {
if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
this.game.sound.decode(this.key, this);
}
}
} else {
console.log('Sound play Audio');
//console.log('Sound play Audio');
if(this.game.cache.getSound(this.key).locked) {
console.log('tried playing locked sound, pending set, reload started');
//console.log('tried playing locked sound, pending set, reload started');
this.game.cache.reloadSound(this.key);
this.pendingPlayback = true;
} else {
console.log('sound not locked, state?', this._sound.readyState);
//console.log('sound not locked, state?', this._sound.readyState);
if(this._sound && this._sound.readyState == 4) {
if(this.duration == 0) {
this.duration = this.totalDuration * 1000;
}
console.log('playing', this._sound);
//console.log('playing', this._sound);
this._sound.currentTime = this.position;
this._sound.muted = this._muted;
this._sound.volume = this._volume;
@ -14364,6 +14412,7 @@ var Phaser;
* Stop playing this sound.
*/
function () {
console.log('Sound.stop', this.currentMarker);
if(this.isPlaying && this._sound) {
if(this.usingWebAudio) {
if(typeof this._sound.stop === 'undefined') {
@ -14375,10 +14424,11 @@ var Phaser;
this._sound.pause();
this._sound.currentTime = 0;
}
this.isPlaying = false;
this.currentMarker = '';
this.onStop.dispatch(this);
}
this.isPlaying = false;
var prevMarker = this.currentMarker;
this.currentMarker = '';
this.onStop.dispatch(this, prevMarker);
};
Object.defineProperty(Sound.prototype, "mute", {
get: /**
@ -14482,7 +14532,7 @@ var Phaser;
this.channels = 1;
}
if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
console.log('iOS Touch Locked');
//console.log('iOS Touch Locked');
this.game.input.touch.callbackContext = this;
this.game.input.touch.touchStartCallback = this.unlock;
this.game.input.mouse.callbackContext = this;
@ -14534,9 +14584,9 @@ var Phaser;
if(this.touchLocked == false) {
return;
}
console.log('SoundManager touch unlocked');
//console.log('SoundManager touch unlocked');
if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
console.log('create empty buffer');
//console.log('create empty buffer');
// Create empty buffer and play it
var buffer = this.context.createBuffer(1, 1, 22050);
this._unlockSource = this.context.createBufferSource();
@ -14545,7 +14595,7 @@ var Phaser;
this._unlockSource.noteOn(0);
} else {
// Create an Audio tag?
console.log('create audio tag');
//console.log('create audio tag');
this.touchLocked = false;
this._unlockSource = null;
this.game.input.touch.callbackContext = null;
@ -14936,7 +14986,7 @@ var Phaser;
var _this = this;
// We can't do anything about the status bars in iPads, web apps or desktops
if(this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false) {
document.documentElement.style.minHeight = '5000px';
document.documentElement.style.minHeight = '2000px';
this._startHeight = window.innerHeight;
if(this._game.device.android && this._game.device.chrome == false) {
window.scrollTo(0, 1);
@ -14945,7 +14995,7 @@ var Phaser;
}
}
if(this._check == null) {
this._iterations = 40;
this._iterations = 10;
this._check = window.setInterval(function () {
return _this.setScreenSize();
}, 10);
@ -15425,16 +15475,12 @@ var Phaser;
*/
function (event) {
if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
if(this._game.paused == false && this.disablePauseScreen == false) {
if(this._game.paused == false) {
this.pauseGame();
} else {
this._game.paused = true;
}
} else {
if(this._game.paused == true && this.disablePauseScreen == false) {
if(this._game.paused == true) {
this.resumeGame();
} else {
this._game.paused = false;
}
}
};