From 5ed28ab803635d244ec4c6218e998dc9dff4fcff Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Wed, 9 Dec 2015 19:25:21 -0500 Subject: [PATCH] Fix to support Phaser v2.4.4 --- bower.json | 27 +++++++++++++++++++++ dist/phaser-kinetic-scrolling-plugin.js | 9 +++++-- dist/phaser-kinetic-scrolling-plugin.min.js | 2 +- package.json | 4 +-- src/phaser-kinetic-scrolling-plugin.js | 9 +++++-- 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..008142f --- /dev/null +++ b/bower.json @@ -0,0 +1,27 @@ +{ + "name": "phaser-kinetic-scrolling-plugin", + "version": "1.0.2", + "homepage": "https://github.com/jdnichollsc/Phaser-Kinetic-Scrolling-Plugin", + "authors": [ + "Juan David Nicholls Cardona " + ], + "description": "Kinetic Scrolling Plugin for Phaser Framework", + "main": "./dist/phaser-kinetic-scrolling-plugin.min.js", + "keywords": [ + "phaser", + "scroll", + "camera", + "vertical", + "horizontal", + "mousewheel", + "kinetic" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/dist/phaser-kinetic-scrolling-plugin.js b/dist/phaser-kinetic-scrolling-plugin.js index 2ffccd5..8f98c68 100644 --- a/dist/phaser-kinetic-scrolling-plugin.js +++ b/dist/phaser-kinetic-scrolling-plugin.js @@ -3,7 +3,7 @@ * @author Juan Nicholls * @copyright 2015 Juan Nicholls - http://jdnichollsc.github.io/Phaser-Kinetic-Scrolling-Plugin/ * @license {@link http://opensource.org/licenses/MIT} - * @version 1.0.1 + * @version 1.0.2 */ (function (Phaser) { @@ -256,7 +256,12 @@ this.game.input.onDown.remove(this.beginMove, this); - this.game.input.deleteMoveCallback(this.callbackID); + if(this.callbackID){ + this.game.input.deleteMoveCallback(this.callbackID); + } + else{ + this.game.input.deleteMoveCallback(this.moveCamera, this); + } this.game.input.onUp.remove(this.endMove, this); diff --git a/dist/phaser-kinetic-scrolling-plugin.min.js b/dist/phaser-kinetic-scrolling-plugin.min.js index ff5feb2..af5b8d2 100644 --- a/dist/phaser-kinetic-scrolling-plugin.min.js +++ b/dist/phaser-kinetic-scrolling-plugin.min.js @@ -1 +1 @@ -!function(t){"use strict";t.Plugin.KineticScrolling=function(i,e){t.Plugin.call(this,i,e),this.dragging=!1,this.timestamp=0,this.callbackID=0,this.targetX=0,this.targetY=0,this.autoScrollX=!1,this.autoScrollY=!1,this.startX=0,this.startY=0,this.velocityX=0,this.velocityY=0,this.amplitudeX=0,this.amplitudeY=0,this.directionWheel=0,this.velocityWheelX=0,this.velocityWheelY=0,this.settings={kineticMovement:!0,timeConstantScroll:325,horizontalScroll:!0,verticalScroll:!1,horizontalWheel:!0,verticalWheel:!1,deltaWheel:40}},t.Plugin.KineticScrolling.prototype=Object.create(t.Plugin.prototype),t.Plugin.KineticScrolling.prototype.constructor=t.Plugin.KineticScrolling,t.Plugin.KineticScrolling.prototype.configure=function(t){if(t)for(var i in t)this.settings.hasOwnProperty(i)&&(this.settings[i]=t[i])},t.Plugin.KineticScrolling.prototype.start=function(){this.game.input.onDown.add(this.beginMove,this),this.callbackID=this.game.input.addMoveCallback(this.moveCamera,this),this.game.input.onUp.add(this.endMove,this),this.game.input.mouse.mouseWheelCallback=this.mouseWheel.bind(this)},t.Plugin.KineticScrolling.prototype.beginMove=function(){this.startX=this.game.input.x,this.startY=this.game.input.y,this.dragging=!0,this.timestamp=Date.now(),this.velocityY=this.amplitudeY=this.velocityX=this.amplitudeX=0},t.Plugin.KineticScrolling.prototype.moveCamera=function(t,i,e){if(this.dragging){this.now=Date.now();var s=this.now-this.timestamp;if(this.timestamp=this.now,this.settings.horizontalScroll){var l=i-this.startX;this.startX=i,this.velocityX=.8*(1e3*l/(1+s))+.2*this.velocityX,this.game.camera.x-=l}if(this.settings.verticalScroll){var l=e-this.startY;this.startY=e,this.velocityY=.8*(1e3*l/(1+s))+.2*this.velocityY,this.game.camera.y-=l}}},t.Plugin.KineticScrolling.prototype.endMove=function(){this.dragging=!1,this.autoScrollX=!1,this.autoScrollY=!1,this.settings.kineticMovement&&(this.now=Date.now(),(this.velocityX>10||this.velocityX<-10)&&(this.amplitudeX=.8*this.velocityX,this.targetX=Math.round(this.game.camera.x-this.amplitudeX),this.autoScrollX=!0),(this.velocityY>10||this.velocityY<-10)&&(this.amplitudeY=.8*this.velocityY,this.targetY=Math.round(this.game.camera.y-this.amplitudeY),this.autoScrollY=!0))},t.Plugin.KineticScrolling.prototype.update=function(){if(this.elapsed=Date.now()-this.timestamp,this.autoScrollX&&0!=this.amplitudeX){var t=-this.amplitudeX*Math.exp(-this.elapsed/this.settings.timeConstantScroll);t>.5||-.5>t?this.game.camera.x=this.targetX-t:(this.autoScrollX=!1,this.game.camera.x=this.targetX)}if(this.autoScrollY&&0!=this.amplitudeY){var t=-this.amplitudeY*Math.exp(-this.elapsed/this.settings.timeConstantScroll);t>.5||-.5>t?this.game.camera.y=this.targetY-t:(this.autoScrollY=!1,this.game.camera.y=this.targetY)}this.settings.horizontalWheel&&(this.velocityWheelX<-.1||this.velocityWheelX>.1)&&(this.game.camera.x-=this.velocityWheelX,this.velocityWheelX*=.95),this.settings.verticalWheel&&(this.velocityWheelY<-.1||this.velocityWheelY>.1)&&(this.game.camera.y-=this.velocityWheelY,this.velocityWheelY*=.95)},t.Plugin.KineticScrolling.prototype.mouseWheel=function(t){if(this.settings.horizontalWheel||this.settings.verticalWheel){t.preventDefault();var i=120*this.game.input.mouse.wheelDelta/this.settings.deltaWheel;this.directionWheel!=this.game.input.mouse.wheelDelta&&(this.velocityWheelX=0,this.velocityWheelY=0,this.directionWheel=this.game.input.mouse.wheelDelta),this.settings.horizontalWheel&&(this.autoScrollX=!1,this.velocityWheelX+=i),this.settings.verticalWheel&&(this.autoScrollY=!1,this.velocityWheelY+=i)}},t.Plugin.KineticScrolling.prototype.stop=function(){this.game.input.onDown.remove(this.beginMove,this),this.game.input.deleteMoveCallback(this.callbackID),this.game.input.onUp.remove(this.endMove,this),this.game.input.mouse.mouseWheelCallback=null}}(Phaser); \ No newline at end of file +!function(t){"use strict";t.Plugin.KineticScrolling=function(i,e){t.Plugin.call(this,i,e),this.dragging=!1,this.timestamp=0,this.callbackID=0,this.targetX=0,this.targetY=0,this.autoScrollX=!1,this.autoScrollY=!1,this.startX=0,this.startY=0,this.velocityX=0,this.velocityY=0,this.amplitudeX=0,this.amplitudeY=0,this.directionWheel=0,this.velocityWheelX=0,this.velocityWheelY=0,this.settings={kineticMovement:!0,timeConstantScroll:325,horizontalScroll:!0,verticalScroll:!1,horizontalWheel:!0,verticalWheel:!1,deltaWheel:40}},t.Plugin.KineticScrolling.prototype=Object.create(t.Plugin.prototype),t.Plugin.KineticScrolling.prototype.constructor=t.Plugin.KineticScrolling,t.Plugin.KineticScrolling.prototype.configure=function(t){if(t)for(var i in t)this.settings.hasOwnProperty(i)&&(this.settings[i]=t[i])},t.Plugin.KineticScrolling.prototype.start=function(){this.game.input.onDown.add(this.beginMove,this),this.callbackID=this.game.input.addMoveCallback(this.moveCamera,this),this.game.input.onUp.add(this.endMove,this),this.game.input.mouse.mouseWheelCallback=this.mouseWheel.bind(this)},t.Plugin.KineticScrolling.prototype.beginMove=function(){this.startX=this.game.input.x,this.startY=this.game.input.y,this.dragging=!0,this.timestamp=Date.now(),this.velocityY=this.amplitudeY=this.velocityX=this.amplitudeX=0},t.Plugin.KineticScrolling.prototype.moveCamera=function(t,i,e){if(this.dragging){this.now=Date.now();var s=this.now-this.timestamp;if(this.timestamp=this.now,this.settings.horizontalScroll){var l=i-this.startX;this.startX=i,this.velocityX=.8*(1e3*l/(1+s))+.2*this.velocityX,this.game.camera.x-=l}if(this.settings.verticalScroll){var l=e-this.startY;this.startY=e,this.velocityY=.8*(1e3*l/(1+s))+.2*this.velocityY,this.game.camera.y-=l}}},t.Plugin.KineticScrolling.prototype.endMove=function(){this.dragging=!1,this.autoScrollX=!1,this.autoScrollY=!1,this.settings.kineticMovement&&(this.now=Date.now(),(this.velocityX>10||this.velocityX<-10)&&(this.amplitudeX=.8*this.velocityX,this.targetX=Math.round(this.game.camera.x-this.amplitudeX),this.autoScrollX=!0),(this.velocityY>10||this.velocityY<-10)&&(this.amplitudeY=.8*this.velocityY,this.targetY=Math.round(this.game.camera.y-this.amplitudeY),this.autoScrollY=!0))},t.Plugin.KineticScrolling.prototype.update=function(){if(this.elapsed=Date.now()-this.timestamp,this.autoScrollX&&0!=this.amplitudeX){var t=-this.amplitudeX*Math.exp(-this.elapsed/this.settings.timeConstantScroll);t>.5||-.5>t?this.game.camera.x=this.targetX-t:(this.autoScrollX=!1,this.game.camera.x=this.targetX)}if(this.autoScrollY&&0!=this.amplitudeY){var t=-this.amplitudeY*Math.exp(-this.elapsed/this.settings.timeConstantScroll);t>.5||-.5>t?this.game.camera.y=this.targetY-t:(this.autoScrollY=!1,this.game.camera.y=this.targetY)}this.settings.horizontalWheel&&(this.velocityWheelX<-.1||this.velocityWheelX>.1)&&(this.game.camera.x-=this.velocityWheelX,this.velocityWheelX*=.95),this.settings.verticalWheel&&(this.velocityWheelY<-.1||this.velocityWheelY>.1)&&(this.game.camera.y-=this.velocityWheelY,this.velocityWheelY*=.95)},t.Plugin.KineticScrolling.prototype.mouseWheel=function(t){if(this.settings.horizontalWheel||this.settings.verticalWheel){t.preventDefault();var i=120*this.game.input.mouse.wheelDelta/this.settings.deltaWheel;this.directionWheel!=this.game.input.mouse.wheelDelta&&(this.velocityWheelX=0,this.velocityWheelY=0,this.directionWheel=this.game.input.mouse.wheelDelta),this.settings.horizontalWheel&&(this.autoScrollX=!1,this.velocityWheelX+=i),this.settings.verticalWheel&&(this.autoScrollY=!1,this.velocityWheelY+=i)}},t.Plugin.KineticScrolling.prototype.stop=function(){this.game.input.onDown.remove(this.beginMove,this),this.callbackID?this.game.input.deleteMoveCallback(this.callbackID):this.game.input.deleteMoveCallback(this.moveCamera,this),this.game.input.onUp.remove(this.endMove,this),this.game.input.mouse.mouseWheelCallback=null}}(Phaser); \ No newline at end of file diff --git a/package.json b/package.json index efc1a85..1514a3f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "phaser-kinetic-scrolling-plugin", - "version": "1.0.1", - "release": "V 1.0.1", + "version": "1.0.2", + "release": "V 1.0.2", "description": "Kinetic Scrolling Plugin for Phaser Framework", "author": "Juan David Nicholls Cardona ", "logo": "https://raw.github.com/jdnichollsc/Phaser-Kinetic-Scrolling-Plugin/gh-pages/img/plugin.png", diff --git a/src/phaser-kinetic-scrolling-plugin.js b/src/phaser-kinetic-scrolling-plugin.js index 2ffccd5..8f98c68 100644 --- a/src/phaser-kinetic-scrolling-plugin.js +++ b/src/phaser-kinetic-scrolling-plugin.js @@ -3,7 +3,7 @@ * @author Juan Nicholls * @copyright 2015 Juan Nicholls - http://jdnichollsc.github.io/Phaser-Kinetic-Scrolling-Plugin/ * @license {@link http://opensource.org/licenses/MIT} - * @version 1.0.1 + * @version 1.0.2 */ (function (Phaser) { @@ -256,7 +256,12 @@ this.game.input.onDown.remove(this.beginMove, this); - this.game.input.deleteMoveCallback(this.callbackID); + if(this.callbackID){ + this.game.input.deleteMoveCallback(this.callbackID); + } + else{ + this.game.input.deleteMoveCallback(this.moveCamera, this); + } this.game.input.onUp.remove(this.endMove, this);