Socket
Socket
Sign inDemoInstall

phaser-kinetic-scrolling-plugin

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.6 to 1.0.8

2

bower.json
{
"name": "phaser-kinetic-scrolling-plugin",
"version": "1.0.3",
"version": "1.0.8",
"homepage": "https://github.com/jdnichollsc/Phaser-Kinetic-Scrolling-Plugin",

@@ -5,0 +5,0 @@ "authors": [

@@ -6,3 +6,3 @@ /**

* @license {@link http://opensource.org/licenses/MIT}
* @version 1.0.6
* @version 1.0.8
*/

@@ -187,3 +187,3 @@

var updateX = 0;
if (this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right) {
if (this.canCameraMoveX()) {
updateX = deltaX;

@@ -193,3 +193,3 @@ }

var updateY = 0;
if (this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height) {
if (this.canCameraMoveY()) {
updateY = deltaY;

@@ -204,2 +204,18 @@ }

/**
* Indicates when camera can move in the x axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveX = function () {
return this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right;
};
/**
* Indicates when camera can move in the y axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveY = function () {
return this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height;
};
/**
* Event triggered when a pointer is released, calculates the automatic scrolling.

@@ -263,3 +279,3 @@ */

delta = -this.amplitudeX * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveX() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.x = this.targetX - delta;

@@ -276,3 +292,3 @@ }

delta = -this.amplitudeY * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveY() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.y = this.targetY - delta;

@@ -279,0 +295,0 @@ }

@@ -1,1 +0,1 @@

!function(t){"use strict";t.Plugin.KineticScrolling=function(i,e){t.Plugin.call(this,i,e),this.pointerId=null,this.dragging=!1,this.pressedDown=!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.thresholdOfTapTime=100,this.thresholdOfTapDistance=10,this.settings={kineticMovement:!0,timeConstantScroll:325,horizontalScroll:!0,verticalScroll:!1,horizontalWheel:!0,verticalWheel:!1,deltaWheel:40,onUpdate:null}},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(t){this.pointerId=t.id,this.startX=this.game.input.x,this.startY=this.game.input.y,this.screenX=t.screenX,this.screenY=t.screenY,this.pressedDown=!0,this.timestamp=Date.now(),this.beginTime=this.timestamp,this.velocityY=this.amplitudeY=this.velocityX=this.amplitudeX=0},t.Plugin.KineticScrolling.prototype.moveCamera=function(t,i,e){if(this.pressedDown&&this.pointerId===t.id){this.now=Date.now();var s=this.now-this.timestamp;this.timestamp=this.now;var h=0,a=0;if(!(this.now-this.beginTime<this.thresholdOfTapTime&&Math.abs(t.screenY-this.screenY)<this.thresholdOfTapDistance&&Math.abs(t.screenX-this.screenX)<this.thresholdOfTapDistance)&&(this.settings.horizontalScroll&&(h=i-this.startX,0!==h&&(this.dragging=!0),this.startX=i,this.velocityX=.8*(1e3*h/(1+s))+.2*this.velocityX,this.game.camera.x-=h),this.settings.verticalScroll&&(a=e-this.startY,0!==a&&(this.dragging=!0),this.startY=e,this.velocityY=.8*(1e3*a/(1+s))+.2*this.velocityY,this.game.camera.y-=a),"function"==typeof this.settings.onUpdate)){var l=0;this.game.camera.x>0&&this.game.camera.x+this.game.camera.width<this.game.camera.bounds.right&&(l=h);var o=0;this.game.camera.y>0&&this.game.camera.y+this.game.camera.height<this.game.camera.bounds.height&&(o=a),this.settings.onUpdate(l,o)}}},t.Plugin.KineticScrolling.prototype.endMove=function(){this.pointerId=null,this.pressedDown=!1,this.autoScrollX=!1,this.autoScrollY=!1,this.settings.kineticMovement&&(this.now=Date.now(),this.game.input.activePointer.withinGame&&((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)),this.game.input.activePointer.withinGame||(this.velocityWheelXAbs=Math.abs(this.velocityWheelX),this.velocityWheelYAbs=Math.abs(this.velocityWheelY),this.settings.horizontalScroll&&(this.velocityWheelXAbs<.1||!this.game.input.activePointer.withinGame)&&(this.autoScrollX=!0),this.settings.verticalScroll&&(this.velocityWheelYAbs<.1||!this.game.input.activePointer.withinGame)&&(this.autoScrollY=!0)))},t.Plugin.KineticScrolling.prototype.update=function(){this.elapsed=Date.now()-this.timestamp,this.velocityWheelXAbs=Math.abs(this.velocityWheelX),this.velocityWheelYAbs=Math.abs(this.velocityWheelY);var t=0;this.autoScrollX&&0!=this.amplitudeX&&(t=-this.amplitudeX*Math.exp(-this.elapsed/this.settings.timeConstantScroll),t>.5||t<-.5?this.game.camera.x=this.targetX-t:(this.autoScrollX=!1,this.game.camera.x=this.targetX)),this.autoScrollY&&0!=this.amplitudeY&&(t=-this.amplitudeY*Math.exp(-this.elapsed/this.settings.timeConstantScroll),t>.5||t<-.5?this.game.camera.y=this.targetY-t:(this.autoScrollY=!1,this.game.camera.y=this.targetY)),this.autoScrollX||this.autoScrollY||(this.dragging=!1),this.settings.horizontalWheel&&this.velocityWheelXAbs>.1&&(this.dragging=!0,this.amplitudeX=0,this.autoScrollX=!1,this.game.camera.x-=this.velocityWheelX,this.velocityWheelX*=.95),this.settings.verticalWheel&&this.velocityWheelYAbs>.1&&(this.dragging=!0,this.autoScrollY=!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;if(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,"function"==typeof this.settings.onUpdate)){var e=0;this.game.camera.x>0&&this.game.camera.x+this.game.camera.width<this.game.camera.bounds.width&&(e=i),this.settings.onUpdate(e,0)}if(this.settings.verticalWheel&&(this.autoScrollY=!1,this.velocityWheelY+=i,"function"==typeof this.settings.onUpdate)){var s=0;this.game.camera.y>0&&this.game.camera.y+this.game.camera.height<this.game.camera.bounds.height&&(s=i),this.settings.onUpdate(0,s)}}},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);
!function(t){"use strict";t.Plugin.KineticScrolling=function(i,e){t.Plugin.call(this,i,e),this.pointerId=null,this.dragging=!1,this.pressedDown=!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.thresholdOfTapTime=100,this.thresholdOfTapDistance=10,this.settings={kineticMovement:!0,timeConstantScroll:325,horizontalScroll:!0,verticalScroll:!1,horizontalWheel:!0,verticalWheel:!1,deltaWheel:40,onUpdate:null}},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(t){this.pointerId=t.id,this.startX=this.game.input.x,this.startY=this.game.input.y,this.screenX=t.screenX,this.screenY=t.screenY,this.pressedDown=!0,this.timestamp=Date.now(),this.beginTime=this.timestamp,this.velocityY=this.amplitudeY=this.velocityX=this.amplitudeX=0},t.Plugin.KineticScrolling.prototype.moveCamera=function(t,i,e){if(this.pressedDown&&this.pointerId===t.id){this.now=Date.now();var s=this.now-this.timestamp;this.timestamp=this.now;var h=0,a=0;if(!(this.now-this.beginTime<this.thresholdOfTapTime&&Math.abs(t.screenY-this.screenY)<this.thresholdOfTapDistance&&Math.abs(t.screenX-this.screenX)<this.thresholdOfTapDistance)&&(this.settings.horizontalScroll&&(h=i-this.startX,0!==h&&(this.dragging=!0),this.startX=i,this.velocityX=.8*(1e3*h/(1+s))+.2*this.velocityX,this.game.camera.x-=h),this.settings.verticalScroll&&(a=e-this.startY,0!==a&&(this.dragging=!0),this.startY=e,this.velocityY=.8*(1e3*a/(1+s))+.2*this.velocityY,this.game.camera.y-=a),"function"==typeof this.settings.onUpdate)){var l=0;this.canCameraMoveX()&&(l=h);var o=0;this.canCameraMoveY()&&(o=a),this.settings.onUpdate(l,o)}}},t.Plugin.KineticScrolling.prototype.canCameraMoveX=function(){return this.game.camera.x>0&&this.game.camera.x+this.game.camera.width<this.game.camera.bounds.right},t.Plugin.KineticScrolling.prototype.canCameraMoveY=function(){return this.game.camera.y>0&&this.game.camera.y+this.game.camera.height<this.game.camera.bounds.height},t.Plugin.KineticScrolling.prototype.endMove=function(){this.pointerId=null,this.pressedDown=!1,this.autoScrollX=!1,this.autoScrollY=!1,this.settings.kineticMovement&&(this.now=Date.now(),this.game.input.activePointer.withinGame&&((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)),this.game.input.activePointer.withinGame||(this.velocityWheelXAbs=Math.abs(this.velocityWheelX),this.velocityWheelYAbs=Math.abs(this.velocityWheelY),this.settings.horizontalScroll&&(this.velocityWheelXAbs<.1||!this.game.input.activePointer.withinGame)&&(this.autoScrollX=!0),this.settings.verticalScroll&&(this.velocityWheelYAbs<.1||!this.game.input.activePointer.withinGame)&&(this.autoScrollY=!0)))},t.Plugin.KineticScrolling.prototype.update=function(){this.elapsed=Date.now()-this.timestamp,this.velocityWheelXAbs=Math.abs(this.velocityWheelX),this.velocityWheelYAbs=Math.abs(this.velocityWheelY);var t=0;this.autoScrollX&&0!=this.amplitudeX&&(t=-this.amplitudeX*Math.exp(-this.elapsed/this.settings.timeConstantScroll),this.canCameraMoveX()&&(t>.5||t<-.5)?this.game.camera.x=this.targetX-t:(this.autoScrollX=!1,this.game.camera.x=this.targetX)),this.autoScrollY&&0!=this.amplitudeY&&(t=-this.amplitudeY*Math.exp(-this.elapsed/this.settings.timeConstantScroll),this.canCameraMoveY()&&(t>.5||t<-.5)?this.game.camera.y=this.targetY-t:(this.autoScrollY=!1,this.game.camera.y=this.targetY)),this.autoScrollX||this.autoScrollY||(this.dragging=!1),this.settings.horizontalWheel&&this.velocityWheelXAbs>.1&&(this.dragging=!0,this.amplitudeX=0,this.autoScrollX=!1,this.game.camera.x-=this.velocityWheelX,this.velocityWheelX*=.95),this.settings.verticalWheel&&this.velocityWheelYAbs>.1&&(this.dragging=!0,this.autoScrollY=!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;if(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,"function"==typeof this.settings.onUpdate)){var e=0;this.game.camera.x>0&&this.game.camera.x+this.game.camera.width<this.game.camera.bounds.width&&(e=i),this.settings.onUpdate(e,0)}if(this.settings.verticalWheel&&(this.autoScrollY=!1,this.velocityWheelY+=i,"function"==typeof this.settings.onUpdate)){var s=0;this.game.camera.y>0&&this.game.camera.y+this.game.camera.height<this.game.camera.bounds.height&&(s=i),this.settings.onUpdate(0,s)}}},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);

@@ -6,3 +6,3 @@ /**

* @license {@link http://opensource.org/licenses/MIT}
* @version 1.0.6
* @version 1.0.8
*/

@@ -187,3 +187,3 @@

var updateX = 0;
if (this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right) {
if (this.canCameraMoveX()) {
updateX = deltaX;

@@ -193,3 +193,3 @@ }

var updateY = 0;
if (this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height) {
if (this.canCameraMoveY()) {
updateY = deltaY;

@@ -204,2 +204,18 @@ }

/**
* Indicates when camera can move in the x axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveX = function () {
return this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right;
};
/**
* Indicates when camera can move in the y axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveY = function () {
return this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height;
};
/**
* Event triggered when a pointer is released, calculates the automatic scrolling.

@@ -263,3 +279,3 @@ */

delta = -this.amplitudeX * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveX() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.x = this.targetX - delta;

@@ -276,3 +292,3 @@ }

delta = -this.amplitudeY * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveY() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.y = this.targetY - delta;

@@ -279,0 +295,0 @@ }

{
"name": "phaser-kinetic-scrolling-plugin",
"version": "1.0.6",
"release": "V 1.0.6",
"version": "1.0.8",
"release": "V 1.0.8",
"description": "Kinetic Scrolling Plugin for Phaser Framework",

@@ -6,0 +6,0 @@ "author": "Juan David Nicholls Cardona <jdnichollsc@hotmail.com>",

@@ -5,3 +5,3 @@ # Kinetic Scrolling Plugin for Phaser Framework

The vertical and horizontal scrolling is very useful feature in the games for example to display a section of levels and with this plugin you can simulate the scrolling within a **canvas** element of **HTML5**... so check this awesome plugin to **Phaser Framework**!
The vertical and horizontal scrolling is a very useful feature in the games for example to display a section of levels and with this plugin you can simulate the scrolling within a **canvas** element of **HTML5**... so check this awesome plugin for **Phaser Framework**!

@@ -107,2 +107,3 @@ > Kinetic scrolling based on http://ariya.ofilabs.com/2013/11/javascript-kinetic-scrolling-part-2.html

## Collaborators
[<img alt="VitaZheltyakov" src="https://avatars1.githubusercontent.com/u/4193707?s=117&v=4" width="117">](https://github.com/daniel-mf) |
[<img alt="VitaZheltyakov" src="https://avatars3.githubusercontent.com/u/5693437?v=3&s=117" width="117">](https://github.com/VitaZheltyakov) |

@@ -112,4 +113,4 @@ [<img alt="iamchristopher" src="https://avatars2.githubusercontent.com/u/5909516?v=3&s=117" width="117">](https://github.com/iamchristopher) |

[<img alt="jdnichollsc" src="https://avatars3.githubusercontent.com/u/2154886?v=3&s=117" width="117">](https://github.com/jdnichollsc) |
:---: |:---: |:---: |:---: |
[Vitaliy](mailto:vita-zhelt@yandex.ru) | [Chris Wright](https://twitter.com/jorbascrumps) | [Daaaabeen](mailto:dianbin.lee@gmail.com) | [Nicholls](mailto:jdnichollsc@hotmail.com) |
:---: |:---: |:---: |:---: |:---: |
[Daniel](mailto:echo.dmf@gmail.com) | [Vitaliy](mailto:vita-zhelt@yandex.ru) | [Chris Wright](https://twitter.com/jorbascrumps) | [Daaaabeen](mailto:dianbin.lee@gmail.com) | [Nicholls](mailto:jdnichollsc@hotmail.com) |

@@ -116,0 +117,0 @@ ## Other Projects

@@ -6,3 +6,3 @@ /**

* @license {@link http://opensource.org/licenses/MIT}
* @version 1.0.6
* @version 1.0.8
*/

@@ -187,3 +187,3 @@

var updateX = 0;
if (this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right) {
if (this.canCameraMoveX()) {
updateX = deltaX;

@@ -193,3 +193,3 @@ }

var updateY = 0;
if (this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height) {
if (this.canCameraMoveY()) {
updateY = deltaY;

@@ -204,2 +204,18 @@ }

/**
* Indicates when camera can move in the x axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveX = function () {
return this.game.camera.x > 0 && this.game.camera.x + this.game.camera.width < this.game.camera.bounds.right;
};
/**
* Indicates when camera can move in the y axis
* @return {boolean}
*/
Phaser.Plugin.KineticScrolling.prototype.canCameraMoveY = function () {
return this.game.camera.y > 0 && this.game.camera.y + this.game.camera.height < this.game.camera.bounds.height;
};
/**
* Event triggered when a pointer is released, calculates the automatic scrolling.

@@ -263,3 +279,3 @@ */

delta = -this.amplitudeX * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveX() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.x = this.targetX - delta;

@@ -276,3 +292,3 @@ }

delta = -this.amplitudeY * Math.exp(-this.elapsed / this.settings.timeConstantScroll);
if (delta > 0.5 || delta < -0.5) {
if (this.canCameraMoveY() && (delta > 0.5 || delta < -0.5)) {
this.game.camera.y = this.targetY - delta;

@@ -279,0 +295,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc