IFrame interface for animation

This commit is contained in:
Alexey Kalmakov
2019-10-02 23:39:53 +03:00
parent 23661c6c5a
commit 150b8bcea3
2 changed files with 14 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { glob } from './Global'; import { glob } from './Global';
import { Layer } from './Layer'; import { Layer } from './Layer';
import { IFrame, AnimationFn } from './types';
var now = (function() { var now = (function() {
if (glob.performance && glob.performance.now) { if (glob.performance && glob.performance.now) {
@@ -17,7 +18,7 @@ var now = (function() {
* Animation constructor. * Animation constructor.
* @constructor * @constructor
* @memberof Konva * @memberof Konva
* @param {Function} func function executed on each animation frame. The function is passed a frame object, which contains * @param {AnimationFn} func function executed on each animation frame. The function is passed a frame object, which contains
* timeDiff, lastTime, time, and frameRate properties. The timeDiff property is the number of milliseconds that have passed * timeDiff, lastTime, time, and frameRate properties. The timeDiff property is the number of milliseconds that have passed
* since the last animation frame. The lastTime property is time in milliseconds that elapsed from the moment the animation started * since the last animation frame. The lastTime property is time in milliseconds that elapsed from the moment the animation started
* to the last animation frame. The time property is the time in milliseconds that elapsed from the moment the animation started * to the last animation frame. The time property is the time in milliseconds that elapsed from the moment the animation started
@@ -37,19 +38,19 @@ var now = (function() {
* anim.start(); * anim.start();
*/ */
export class Animation { export class Animation {
func: () => boolean; func: AnimationFn;
id = Animation.animIdCounter++; id = Animation.animIdCounter++;
layers: Layer[]; layers: Layer[];
frame = { frame : IFrame = {
time: 0, time: 0,
timeDiff: 0, timeDiff: 0,
lastTime: now(), lastTime: now(),
frameRate: 0 frameRate: 0
}; };
constructor(func, layers?) { constructor(func: AnimationFn, layers?) {
this.func = func; this.func = func;
this.setLayers(layers); this.setLayers(layers);
} }

View File

@@ -18,6 +18,15 @@ export interface IRect {
height: number; height: number;
} }
export interface IFrame {
time: number;
timeDiff: number;
lastTime: any;
frameRate: number;
}
export type AnimationFn = (frame?: IFrame) => boolean|void;
export enum KonvaNodeEvent { export enum KonvaNodeEvent {
mouseover = 'mouseover', mouseover = 'mouseover',
mouseout = 'mouseout', mouseout = 'mouseout',