added play, pause and stop events, closes #53

This commit is contained in:
javi 2014-11-01 17:25:08 +01:00
parent 589a29acfb
commit fe27c0b515
2 changed files with 14 additions and 1 deletions

View File

@ -37,6 +37,7 @@
start: function() {
this.running = true;
requestAnimationFrame(this._tick);
this.options.onStart && this.options.onStart();
},
isRunning: function() {
@ -46,6 +47,7 @@
stop: function() {
this.pause();
this.time(0);
this.options.onStop && this.options.onStop();
},
// real animation time
@ -96,6 +98,7 @@
pause: function() {
this.running = false;
cancelAnimationFrame(this._tick);
this.options.onPause && this.options.onPause();
},
_tick: function() {

View File

@ -37,7 +37,17 @@ L.TorqueLayer = L.CanvasLayer.extend({
if(self.key !== k) {
self.setKey(k, { direct: true });
}
}, torque.clone(options));
}, torque.extend(torque.clone(options), {
onPause: function() {
self.fire('pause');
},
onStop: function() {
self.fire('stop');
},
onStart: function() {
self.fire('play');
}
}));
this.play = this.animator.start.bind(this.animator);
this.stop = this.animator.stop.bind(this.animator);