Created
January 2, 2013 13:16
-
-
Save volkans80/4434531 to your computer and use it in GitHub Desktop.
Edge pan component for Isogenic Engine 1.1.0
Add it to viewport entity and use detectarea (pixels of edges), speed properties.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EdgePan = IgeClass.extend({ | |
classId: 'EdgePan', | |
componentId: 'edgepan', | |
init: function (entity, options) { | |
var self = this; | |
self._entity = entity; | |
self._options = options; | |
self.edgePanEntity = new IgeEntity() | |
.id('edgePanEntity') | |
.depth(1) | |
.translateTo(0, 0, 0) | |
.drawBounds(false) | |
.drawBoundsData(false) | |
.width(1) | |
.height(1) | |
.mount(ige); | |
self.edgePanEntity.tick = function (ctx) { | |
if (self.xStep !== 0 || self.yStep !== 0) { | |
self.edgePanEntity.translateBy(self.xStep, self.yStep, 0); | |
} | |
}; | |
entity.camera.trackTranslate(self.edgePanEntity); | |
self.xStep = 0; | |
self.yStep = 0; | |
self._detectArea = 30; | |
self._speed = 7; | |
ige.input.on('mouseMove', function (event, x, y, button) { | |
var sp, a=ige._geometry.x2 - self._detectArea, b=ige._geometry.y2 - self._detectArea; | |
if (Math.abs(x) > a) { | |
sp = ((Math.abs(x) - a) / self._detectArea) * self._speed; | |
self.xStep = x < 0 ? -sp : sp; | |
} else { | |
self.xStep = 0; | |
} | |
if (Math.abs(y) > b) { | |
sp = ((Math.abs(y) - b) / self._detectArea) * self._speed; | |
self.yStep = y < 0 ? -sp : sp; | |
} else { | |
self.yStep = 0; | |
} | |
}); | |
}, | |
detectArea: function(value){ | |
if (value!==undefined) { | |
this._detectArea = value; | |
return this._entity; | |
} else { | |
return this._detectArea; | |
} | |
}, | |
speed : function(value){ | |
if (value!==undefined) { | |
this._speed = value; | |
return this._entity; | |
} else { | |
return this._speed; | |
} | |
} | |
}); | |
if (typeof(module) !== 'undefined' && typeof(module.exports) !== 'undefined') { | |
module.exports = EdgePan; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copied from @volkans80 post on usage in another thread for anyone who is interested: