AnimationTool/app/frame_handler.ts

30 lines
789 B
TypeScript
Raw Normal View History

2019-09-25 03:16:07 +00:00
export class FrameHandler {
private filenames: string[] = [];
private currentFrame: number = 0;
private currentImageDiv: HTMLElement;
constructor(currentImageDiv: HTMLElement) {
this.currentImageDiv = currentImageDiv;
}
public loadFrames(filenames: string[]) {
this.filenames = filenames;
this.currentFrame = 0;
}
public AdvanceFrames(amount: number) {
this.currentFrame += amount;
this.currentFrame %= this.filenames.length;
if (this.currentFrame < 0) {
this.currentFrame = this.filenames.length - 1;
}
this.GoToFrame(this.currentFrame);
}
public GoToFrame(frame: number) {
this.currentFrame = frame;
this.currentImageDiv.innerHTML = `<img src="${this.filenames[this.currentFrame]}"></img>`;
console.log('current frame = ', this.currentFrame);
}
}