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.3 to 1.0.4

examples/example_1.html

0

bower.json

@@ -0,0 +0,0 @@ {

61

dist/phaser-kinetic-scrolling-plugin.js

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

* @license {@link http://opensource.org/licenses/MIT}
* @version 1.0.3
* @version 1.0.4
*/

@@ -25,4 +25,4 @@

this.dragging = false;
this.pressedDown = false;
this.timestamp = 0;

@@ -114,3 +114,3 @@ this.callbackID = 0;

this.dragging = true;
this.pressedDown = true;

@@ -129,3 +129,3 @@ this.timestamp = Date.now();

if (!this.dragging) return;
if (!this.pressedDown) return;

@@ -138,2 +138,3 @@ this.now = Date.now();

var delta = x - this.startX; //Compute move distance
if (delta !== 0) this.dragging = true;
this.startX = x;

@@ -146,2 +147,3 @@ this.velocityX = 0.8 * (1000 * delta / (1 + elapsed)) + 0.2 * this.velocityX;

var delta = y - this.startY; //Compute move distance
if (delta !== 0) this.dragging = true;
this.startY = y;

@@ -158,4 +160,4 @@ this.velocityY = 0.8 * (1000 * delta / (1 + elapsed)) + 0.2 * this.velocityY;

Phaser.Plugin.KineticScrolling.prototype.endMove = function () {
this.dragging = false;
this.pressedDown = false;
this.autoScrollX = false;

@@ -168,20 +170,22 @@ this.autoScrollY = false;

if (this.game.input.activePointer.withinGame && (this.velocityX > 10 || this.velocityX < -10)) {
this.amplitudeX = 0.8 * this.velocityX;
this.targetX = Math.round(this.game.camera.x - this.amplitudeX);
this.autoScrollX = true;
}
if(this.game.input.activePointer.withinGame){
if (this.velocityX > 10 || this.velocityX < -10) {
this.amplitudeX = 0.8 * this.velocityX;
this.targetX = Math.round(this.game.camera.x - this.amplitudeX);
this.autoScrollX = true;
}
if (this.game.input.activePointer.withinGame && (this.velocityY > 10 || this.velocityY < -10)) {
this.amplitudeY = 0.8 * this.velocityY;
this.targetY = Math.round(this.game.camera.y - this.amplitudeY);
this.autoScrollY = true;
if (this.velocityY > 10 || this.velocityY < -10) {
this.amplitudeY = 0.8 * this.velocityY;
this.targetY = Math.round(this.game.camera.y - this.amplitudeY);
this.autoScrollY = true;
}
}
if (!this.game.input.activePointer.withinGame) {
if (this.settings.horizontalScroll) {
this.velocityWheelXAbs = Math.abs(this.velocityWheelX);
this.velocityWheelYAbs = Math.abs(this.velocityWheelY);
if (this.settings.horizontalScroll && (this.velocityWheelXAbs < 0.1 || !this.game.input.activePointer.withinGame)) {
this.autoScrollX = true;
}
if (this.settings.verticalScroll) {
if (this.settings.verticalScroll && (this.velocityWheelYAbs < 0.1 || !this.game.input.activePointer.withinGame)) {
this.autoScrollY = true;

@@ -199,2 +203,4 @@ }

this.elapsed = Date.now() - this.timestamp;
this.velocityWheelXAbs = Math.abs(this.velocityWheelX);
this.velocityWheelYAbs = Math.abs(this.velocityWheelY);

@@ -225,4 +231,10 @@ if (this.autoScrollX && this.amplitudeX != 0) {

if (this.settings.horizontalWheel && (this.velocityWheelX < -0.1 || this.velocityWheelX > 0.1 || !this.game.input.activePointer.withinGame)) {
if(!this.autoScrollX && !this.autoScrollY){
this.dragging = false;
}
if (this.settings.horizontalWheel && this.velocityWheelXAbs > 0.1) {
this.dragging = true;
this.amplitudeX = 0;
this.autoScrollX = false;
this.game.camera.x -= this.velocityWheelX;

@@ -232,4 +244,5 @@ this.velocityWheelX *= 0.95;

if (this.settings.verticalWheel && (this.velocityWheelY < -0.1 || this.velocityWheelY > 0.1 || !this.game.input.activePointer.withinGame)) {
if (this.settings.verticalWheel && this.velocityWheelYAbs > 0.1) {
this.dragging = true;
this.autoScrollY = false;
this.game.camera.y -= this.velocityWheelY;

@@ -292,2 +305,2 @@ this.velocityWheelY *= 0.95;

} (Phaser));
} (Phaser));

@@ -1,1 +0,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 h=i-this.startX;this.startX=i,this.velocityX=.8*(1e3*h/(1+s))+.2*this.velocityX,this.game.camera.x-=h}if(this.settings.verticalScroll){var h=e-this.startY;this.startY=e,this.velocityY=.8*(1e3*h/(1+s))+.2*this.velocityY,this.game.camera.y-=h}}},t.Plugin.KineticScrolling.prototype.endMove=function(){this.dragging=!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.game.input.activePointer.withinGame&&(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.settings.horizontalScroll&&(this.autoScrollX=!0),this.settings.verticalScroll&&(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.input.activePointer.withinGame)&&(this.game.camera.x-=this.velocityWheelX,this.velocityWheelX*=.95),this.settings.verticalWheel&&(this.velocityWheelY<-.1||this.velocityWheelY>.1||!this.game.input.activePointer.withinGame)&&(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);
!function(t){"use strict";t.Plugin.KineticScrolling=function(i,e){t.Plugin.call(this,i,e),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.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.pressedDown=!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.pressedDown){this.now=Date.now();var s=this.now-this.timestamp;if(this.timestamp=this.now,this.settings.horizontalScroll){var 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}if(this.settings.verticalScroll){var h=e-this.startY;0!==h&&(this.dragging=!0),this.startY=e,this.velocityY=.8*(1e3*h/(1+s))+.2*this.velocityY,this.game.camera.y-=h}}},t.Plugin.KineticScrolling.prototype.endMove=function(){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(){if(this.elapsed=Date.now()-this.timestamp,this.velocityWheelXAbs=Math.abs(this.velocityWheelX),this.velocityWheelYAbs=Math.abs(this.velocityWheelY),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.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;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);

@@ -16,2 +16,3 @@ var gulp = require('gulp');

.pipe(gulp.dest("./dist/"))
.pipe(gulp.dest("./examples/js/"))
.pipe(rename({

@@ -18,0 +19,0 @@ extname: ".min.js"

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

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

@@ -56,6 +56,6 @@ # Kinetic Scrolling Plugin for Phaser Framework

init: function () {
//Load the plugin
this.game.kineticScrolling = this.game.plugins.add(Phaser.Plugin.KineticScrolling);
//If you want change the default configuration before start the plugin

@@ -67,3 +67,3 @@ },

this.game.kineticScrolling.start();
//If you want change the default configuration after start the plugin

@@ -96,5 +96,11 @@

## Examples
The repository has three examples of the plugin:
- Horizontal scrolling
- Horizontal scrolling with scrollbar
- Horizontal scrolling and pressing events
# Happy scrolling
Made with <3
<img width="150px" src="http://phaser.azurewebsites.net/assets/nicholls.png" align="right">
<img width="150px" src="http://phaser.azurewebsites.net/assets/nicholls.png" align="right">

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

* @license {@link http://opensource.org/licenses/MIT}
* @version 1.0.3
* @version 1.0.4
*/

@@ -25,4 +25,4 @@

this.dragging = false;
this.pressedDown = false;
this.timestamp = 0;

@@ -114,3 +114,3 @@ this.callbackID = 0;

this.dragging = true;
this.pressedDown = true;

@@ -129,3 +129,3 @@ this.timestamp = Date.now();

if (!this.dragging) return;
if (!this.pressedDown) return;

@@ -138,2 +138,3 @@ this.now = Date.now();

var delta = x - this.startX; //Compute move distance
if (delta !== 0) this.dragging = true;
this.startX = x;

@@ -146,2 +147,3 @@ this.velocityX = 0.8 * (1000 * delta / (1 + elapsed)) + 0.2 * this.velocityX;

var delta = y - this.startY; //Compute move distance
if (delta !== 0) this.dragging = true;
this.startY = y;

@@ -158,4 +160,4 @@ this.velocityY = 0.8 * (1000 * delta / (1 + elapsed)) + 0.2 * this.velocityY;

Phaser.Plugin.KineticScrolling.prototype.endMove = function () {
this.dragging = false;
this.pressedDown = false;
this.autoScrollX = false;

@@ -168,20 +170,22 @@ this.autoScrollY = false;

if (this.game.input.activePointer.withinGame && (this.velocityX > 10 || this.velocityX < -10)) {
this.amplitudeX = 0.8 * this.velocityX;
this.targetX = Math.round(this.game.camera.x - this.amplitudeX);
this.autoScrollX = true;
}
if(this.game.input.activePointer.withinGame){
if (this.velocityX > 10 || this.velocityX < -10) {
this.amplitudeX = 0.8 * this.velocityX;
this.targetX = Math.round(this.game.camera.x - this.amplitudeX);
this.autoScrollX = true;
}
if (this.game.input.activePointer.withinGame && (this.velocityY > 10 || this.velocityY < -10)) {
this.amplitudeY = 0.8 * this.velocityY;
this.targetY = Math.round(this.game.camera.y - this.amplitudeY);
this.autoScrollY = true;
if (this.velocityY > 10 || this.velocityY < -10) {
this.amplitudeY = 0.8 * this.velocityY;
this.targetY = Math.round(this.game.camera.y - this.amplitudeY);
this.autoScrollY = true;
}
}
if (!this.game.input.activePointer.withinGame) {
if (this.settings.horizontalScroll) {
this.velocityWheelXAbs = Math.abs(this.velocityWheelX);
this.velocityWheelYAbs = Math.abs(this.velocityWheelY);
if (this.settings.horizontalScroll && (this.velocityWheelXAbs < 0.1 || !this.game.input.activePointer.withinGame)) {
this.autoScrollX = true;
}
if (this.settings.verticalScroll) {
if (this.settings.verticalScroll && (this.velocityWheelYAbs < 0.1 || !this.game.input.activePointer.withinGame)) {
this.autoScrollY = true;

@@ -199,2 +203,4 @@ }

this.elapsed = Date.now() - this.timestamp;
this.velocityWheelXAbs = Math.abs(this.velocityWheelX);
this.velocityWheelYAbs = Math.abs(this.velocityWheelY);

@@ -225,4 +231,10 @@ if (this.autoScrollX && this.amplitudeX != 0) {

if (this.settings.horizontalWheel && (this.velocityWheelX < -0.1 || this.velocityWheelX > 0.1 || !this.game.input.activePointer.withinGame)) {
if(!this.autoScrollX && !this.autoScrollY){
this.dragging = false;
}
if (this.settings.horizontalWheel && this.velocityWheelXAbs > 0.1) {
this.dragging = true;
this.amplitudeX = 0;
this.autoScrollX = false;
this.game.camera.x -= this.velocityWheelX;

@@ -232,4 +244,5 @@ this.velocityWheelX *= 0.95;

if (this.settings.verticalWheel && (this.velocityWheelY < -0.1 || this.velocityWheelY > 0.1 || !this.game.input.activePointer.withinGame)) {
if (this.settings.verticalWheel && this.velocityWheelYAbs > 0.1) {
this.dragging = true;
this.autoScrollY = false;
this.game.camera.y -= this.velocityWheelY;

@@ -292,2 +305,2 @@ this.velocityWheelY *= 0.95;

} (Phaser));
} (Phaser));
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