2012-09-05 02:09:42 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace("pskl.controller");
|
|
|
|
ns.AnimatedPreviewController = function (framesheet, container, dpi) {
|
|
|
|
this.framesheet = framesheet;
|
|
|
|
this.container = container;
|
2012-09-09 03:12:54 +04:00
|
|
|
|
|
|
|
this.elapsedTime = 0;
|
|
|
|
this.currentIndex = 0;
|
2012-09-05 02:09:42 +04:00
|
|
|
|
|
|
|
this.fps = parseInt($("#preview-fps")[0].value, 10);
|
2012-09-09 01:59:44 +04:00
|
|
|
this.deltaTime = 0;
|
|
|
|
this.previousTime = 0;
|
2012-09-08 17:34:13 +04:00
|
|
|
var renderingOptions = {
|
|
|
|
"dpi": dpi
|
|
|
|
};
|
|
|
|
this.renderer = new pskl.rendering.FrameRenderer(this.container, renderingOptions);
|
2012-09-05 02:09:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
ns.AnimatedPreviewController.prototype.init = function () {
|
|
|
|
$("#preview-fps")[0].addEventListener('change', this.onFPSSliderChange.bind(this));
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.AnimatedPreviewController.prototype.onFPSSliderChange = function(evt) {
|
|
|
|
this.fps = parseInt($("#preview-fps")[0].value, 10);
|
|
|
|
};
|
|
|
|
|
2012-09-09 03:12:54 +04:00
|
|
|
ns.AnimatedPreviewController.prototype.render = function (delta) {
|
|
|
|
this.elapsedTime += delta;
|
|
|
|
var index = Math.floor(this.elapsedTime / (1000/this.fps));
|
|
|
|
if (index != this.currentIndex) {
|
|
|
|
this.currentIndex = index;
|
|
|
|
if (!this.framesheet.hasFrameAtIndex(this.currentIndex)) {
|
|
|
|
this.currentIndex = 0;
|
|
|
|
this.elapsedTime = 0;
|
|
|
|
}
|
|
|
|
this.renderer.render(this.framesheet.getFrameByIndex(this.currentIndex));
|
2012-09-05 02:42:25 +04:00
|
|
|
}
|
2012-09-05 02:09:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|