2012-09-04 22:09:42 +00:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace("pskl.controller");
|
|
|
|
ns.AnimatedPreviewController = function (framesheet, container, dpi) {
|
|
|
|
this.framesheet = framesheet;
|
|
|
|
this.container = container;
|
|
|
|
this.animIndex = 0;
|
|
|
|
|
|
|
|
this.fps = parseInt($("#preview-fps")[0].value, 10);
|
2012-09-08 21:59:44 +00:00
|
|
|
this.deltaTime = 0;
|
|
|
|
this.previousTime = 0;
|
2012-09-08 13:34:13 +00:00
|
|
|
var renderingOptions = {
|
|
|
|
"dpi": dpi
|
|
|
|
};
|
|
|
|
this.renderer = new pskl.rendering.FrameRenderer(this.container, renderingOptions);
|
2012-09-04 22:09:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ns.AnimatedPreviewController.prototype.init = function () {
|
|
|
|
this.initDom();
|
2012-09-08 13:08:00 +00:00
|
|
|
|
|
|
|
this.renderer.init(this.framesheet.getFrameByIndex(this.animIndex));
|
|
|
|
|
2012-09-04 22:09:42 +00:00
|
|
|
this.startAnimationTimer();
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.AnimatedPreviewController.prototype.initDom = 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-08 21:59:44 +00:00
|
|
|
ns.AnimatedPreviewController.prototype.render = function () {
|
2012-09-04 22:42:25 +00:00
|
|
|
if (!this.framesheet.hasFrameAtIndex(this.animIndex)) {
|
|
|
|
this.animIndex = 0;
|
|
|
|
}
|
2012-09-08 13:08:00 +00:00
|
|
|
this.renderer.render(this.framesheet.getFrameByIndex(this.animIndex));
|
2012-09-04 22:42:25 +00:00
|
|
|
this.animIndex++;
|
2012-09-04 22:09:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|