From 16b1913de1d366fb64997414ae54e979681ada60 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 30 Sep 2013 17:12:22 +0100 Subject: [PATCH] * Fixed issue in Sound.play where if you gave a missing marker it would play the whole sound sprite instead. * Button.setFrames will set the current frame based on the button state immediately. * InputHandler now creates the _pointerData array on creation and populates with one empty set of values, so pointerOver etc all work before a start call. * Added Canvas.setUserSelect() to disable touchCallouts and user selections within the canvas. * When the game boots it will now by default disable user-select and touch action events on the game canvas. * Loaded.setPreloadSprite now rounds the width/height values and starts from 1. This fixes canvas draw errors in IE9/10 and Firefox. --- README.md | 8 ++++++ src/core/Stage.js | 3 +++ src/gameobjects/Button.js | 30 +++++++++++++++++++++++ src/input/InputHandler.js | 31 ++++++++++++++++++------ src/loader/Loader.js | 8 +++--- src/sound/Sound.js | 51 ++++++++++++++++++++++++--------------- src/system/Canvas.js | 14 +++++++++++ 7 files changed, 114 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 39287eb0..c414119e 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,14 @@ Version 1.0.7 (in progress in the dev branch) * Made animation looping more robust when skipping frames (thanks XekeDeath) * Fix for incorrect new particle positioning (issue #73) (thanks cottonflop) * Added support for Body.maxVelocity (thanks cocoademon) +* Fixed issue in Sound.play where if you gave a missing marker it would play the whole sound sprite instead. +* Button.setFrames will set the current frame based on the button state immediately. +* InputHandler now creates the _pointerData array on creation and populates with one empty set of values, so pointerOver etc all work before a start call. +* Added Canvas.setUserSelect() to disable touchCallouts and user selections within the canvas. +* When the game boots it will now by default disable user-select and touch action events on the game canvas. +* Loaded.setPreloadSprite now rounds the width/height values and starts from 1. This fixes canvas draw errors in IE9/10 and Firefox. + + * TODO: addMarker hh:mm:ss:ms * TODO: Direction constants diff --git a/src/core/Stage.js b/src/core/Stage.js index 73ea9392..c4deb68c 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -104,6 +104,9 @@ Phaser.Stage.prototype = { return _this.visibilityChange(event); } + Phaser.Canvas.setUserSelect(this.canvas, 'none'); + Phaser.Canvas.setTouchAction(this.canvas, 'none'); + document.addEventListener('visibilitychange', this._onChange, false); document.addEventListener('webkitvisibilitychange', this._onChange, false); document.addEventListener('pagehide', this._onChange, false); diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index ddf0871f..0ed5c731 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -84,10 +84,20 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { if (typeof overFrame === 'string') { this._onOverFrameName = overFrame; + + if (this.input.pointerOver()) + { + this.frameName = overFrame; + } } else { this._onOverFrameID = overFrame; + + if (this.input.pointerOver()) + { + this.frame = overFrame; + } } } @@ -97,11 +107,21 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { { this._onOutFrameName = outFrame; this._onUpFrameName = outFrame; + + if (this.input.pointerOver() == false) + { + this.frameName = outFrame; + } } else { this._onOutFrameID = outFrame; this._onUpFrameID = outFrame; + + if (this.input.pointerOver() == false) + { + this.frame = outFrame; + } } } @@ -110,10 +130,20 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { if (typeof downFrame === 'string') { this._onDownFrameName = downFrame; + + if (this.input.pointerOver()) + { + this.frameName = downFrame; + } } else { this._onDownFrameID = downFrame; + + if (this.input.pointerOver()) + { + this.frame = downFrame; + } } } diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index 6f14400a..2430d12a 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -68,6 +68,24 @@ Phaser.InputHandler = function (sprite) { this._tempPoint = new Phaser.Point; + this._pointerData = []; + + this._pointerData.push({ + id: 0, + x: 0, + y: 0, + isDown: false, + isUp: false, + isOver: false, + isOut: false, + timeOver: 0, + timeOut: 0, + timeDown: 0, + timeUp: 0, + downDuration: 0, + isDragged: false + }); + }; Phaser.InputHandler.prototype = { @@ -84,11 +102,10 @@ Phaser.InputHandler.prototype = { this.game.input.interactiveItems.add(this); this.useHandCursor = useHandCursor; this.priorityID = priority; - this._pointerData = []; for (var i = 0; i < 10; i++) { - this._pointerData.push({ + this._pointerData[i] = { id: i, x: 0, y: 0, @@ -102,7 +119,7 @@ Phaser.InputHandler.prototype = { timeUp: 0, downDuration: 0, isDragged: false - }); + }; } this.snapOffset = new Phaser.Point; @@ -350,10 +367,8 @@ Phaser.InputHandler.prototype = { } } } - else - { - return false; - } + + return false; }, @@ -388,7 +403,7 @@ Phaser.InputHandler.prototype = { */ update: function (pointer) { - if (this.enabled == false || this.sprite.visible == false) + if (this.enabled == false || this.sprite.visible == false || (this.sprite.group && this.sprite.group.visible == false)) { this._pointerOutHandler(pointer); return false; diff --git a/src/loader/Loader.js b/src/loader/Loader.js index da68a3bd..25777679 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -105,12 +105,12 @@ Phaser.Loader.prototype = { if (direction == 0) { // Horizontal crop - this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 0, sprite.height); + this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height); } else { // Vertical crop - this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 0); + this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 1); } sprite.crop = this.preloadSprite.crop; @@ -904,11 +904,11 @@ Phaser.Loader.prototype = { { if (this.preloadSprite.direction == 0) { - this.preloadSprite.crop.width = (this.preloadSprite.width / 100) * this.progress; + this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress); } else { - this.preloadSprite.crop.height = (this.preloadSprite.height / 100) * this.progress; + this.preloadSprite.crop.height = Math.floor((this.preloadSprite.height / 100) * this.progress); } this.preloadSprite.sprite.crop = this.preloadSprite.crop; diff --git a/src/sound/Sound.js b/src/sound/Sound.js index 6a45bc7b..0445b7f6 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -101,6 +101,7 @@ Phaser.Sound = function (game, key, volume, loop) { this.startTime = 0; this.currentTime = 0; this.duration = 0; + this.durationMS = 0; this.stopTime = 0; this.paused = false; this.isPlaying = false; @@ -227,7 +228,7 @@ Phaser.Sound.prototype = { { this.currentTime = this.game.time.now - this.startTime; - if (this.currentTime >= this.duration) + if (this.currentTime >= this.durationMS) { //console.log(this.currentMarker, 'has hit duration'); if (this.usingWebAudio) @@ -289,18 +290,17 @@ Phaser.Sound.prototype = { if (typeof loop == 'undefined') { loop = false; } if (typeof forceRestart == 'undefined') { forceRestart = true; } - console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart); + // console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart); if (this.isPlaying == true && forceRestart == false && this.override == false) { // Use Restart instead - console.log('Use Restart instead'); return; } 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) { @@ -322,28 +322,38 @@ Phaser.Sound.prototype = { this.currentMarker = marker; - if (marker !== '' && this.markers[marker]) + if (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; + if (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; + this.durationMS = this.markers[marker].durationMS; - console.log('Marker Loaded: ', marker, 'start:', this.position, 'end: ', this.duration, 'loop', this.loop); + // console.log('Marker Loaded: ', marker, 'start:', this.position, 'end: ', this.duration, 'loop', this.loop); - this._tempMarker = marker; - this._tempPosition = this.position; - this._tempVolume = this.volume; - this._tempLoop = this.loop; + this._tempMarker = marker; + this._tempPosition = this.position; + this._tempVolume = this.volume; + this._tempLoop = this.loop; + } + else + { + console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist"); + return; + } } else { - console.log('no marker info loaded', marker); + // console.log('no marker info loaded', marker); this.position = position; this.volume = volume; this.loop = loop; this.duration = 0; + this.durationMS = 0; this._tempMarker = marker; this._tempPosition = position; @@ -369,7 +379,9 @@ Phaser.Sound.prototype = { if (this.duration == 0) { - this.duration = this.totalDuration * 1000; + // console.log('duration reset'); + this.duration = this.totalDuration; + this.durationMS = this.totalDuration * 1000; } if (this.loop && marker == '') @@ -393,7 +405,7 @@ Phaser.Sound.prototype = { this.isPlaying = true; this.startTime = this.game.time.now; this.currentTime = 0; - this.stopTime = this.startTime + this.duration; + this.stopTime = this.startTime + this.durationMS; this.onPlay.dispatch(this); } else @@ -426,7 +438,8 @@ Phaser.Sound.prototype = { if (this.duration == 0) { - this.duration = this.totalDuration * 1000; + this.duration = this.totalDuration; + this.durationMS = this.totalDuration * 1000; } // console.log('playing', this._sound); @@ -445,7 +458,7 @@ Phaser.Sound.prototype = { this.isPlaying = true; this.startTime = this.game.time.now; this.currentTime = 0; - this.stopTime = this.startTime + this.duration; + this.stopTime = this.startTime + this.durationMS; this.onPlay.dispatch(this); } else diff --git a/src/system/Canvas.js b/src/system/Canvas.js index 51c44c6b..49eb4b64 100644 --- a/src/system/Canvas.js +++ b/src/system/Canvas.js @@ -108,6 +108,20 @@ Phaser.Canvas = { }, + setUserSelect: function (canvas, value) { + + canvas.style['-webkit-touch-callout'] = value; + canvas.style['-webkit-user-select'] = value; + canvas.style['-khtml-user-select'] = value; + canvas.style['-moz-user-select'] = value; + canvas.style['-ms-user-select'] = value; + canvas.style['user-select'] = value; + canvas.style['-webkit-tap-highlight-color'] = 'rgba(0, 0, 0, 0)'; + + return canvas; + + }, + /** * Adds the given canvas element to the DOM. The canvas will be added as a child of the given parent. * If no parent is given it will be added as a child of the document.body.