Skip to content

Instantly share code, notes, and snippets.

@volkans80
Created January 2, 2013 13:16
Show Gist options
  • Save volkans80/4434531 to your computer and use it in GitHub Desktop.
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.
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;
}
@Irrelon
Copy link

Irrelon commented Jan 4, 2013

Copied from @volkans80 post on usage in another thread for anyone who is interested:

self.vp1 = new IgeViewport()
    .addComponent(EdgePan)
    .id('vp1')
    .depth(1)
    .autoSize(true)
    .scene(self.mainScene)
    .drawBounds(false)
    .drawBoundsData(true)
    .edgepan.detectArea(200)
    .edgepan.speed(15)
    .mount(ige);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment