UNPKG

2d-gaming

Version:

This is an Angular package fo developing 2d games in angular. [Please report issues/questions/any ideas to better help this package](https://github.com/CWestBlue/2d-gaming/issues).

96 lines 3.22 kB
var Animation = (function () { function Animation(length, loop, speed) { this.frame = 0; this.frameItems = []; this.length = length; this.loop = loop; this.speed = speed; for (var i = 0; i <= this.length; i++) { this.frameItems.push(''); } } Animation.prototype.addObject = function (frame, item) { // item.x = this. var newItem = { frame: frame, object: item }; this.frameItems[frame] = newItem; this.fillTimeline(newItem); }; Animation.prototype.start = function () { var _this = this; this.interval = setInterval(function () { _this.animationScript(); }, this.speed); }; Animation.prototype.stop = function () { clearInterval(this.interval); }; Animation.prototype.animationScript = function () { if (this.loop === false) { if (this.frame === this.length) { this.stop(); } } else { if (this.frame === this.length) { this.frame = 0; } } this.frame = this.frame + 1; console.log(this.frameItems[this.frame]); this.frameItems[this.frame].object.update(true); }; Animation.prototype.fillTimeline = function (object) { var nextItem = this.getNextItemFrame(object); var currentItemFrame = object.frame; var difference; if (nextItem) { difference = nextItem.frame - currentItemFrame; } else { difference = this.frameItems.length - currentItemFrame; } for (difference; difference >= 0; difference--) { currentItemFrame = currentItemFrame + 1; console.log(difference); this.frameItems[currentItemFrame] = object; } console.log(this.frameItems); }; // checkCurrentObject() { // this.frameItems.forEach(object => { // if(object === '') { // return; // } else { // let nextItem = this.getNextItemFrame(object); // console.log('first: ' + object.frame) // if(nextItem){ // console.log('next: ' + nextItem.frame); // if(object.frame < this.frame && nextItem.frame > this.frame) { // console.log(object); // this.currentObject = object.object; // } // } else { // console.log(object); // this.currentObject = object.object; // } // } // }) // } Animation.prototype.getNextItemFrame = function (object) { var items = this.frameItems.slice(object.frame + 1, this.length); var end = true; var i = 0; var item; for (end; end; i++) { if (!(items[i] === '')) { item = items[i]; end = false; return items[i]; } } }; return Animation; }()); export { Animation }; //# sourceMappingURL=animator.component.js.map