Skip to content

Commit

Permalink
Interpolation Events
Browse files Browse the repository at this point in the history
  • Loading branch information
CubesterYT committed Jan 28, 2025
1 parent b895b04 commit b25579a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,20 @@ class Runtime extends EventEmitter {
return 'INTERPOLATION_CHANGED';
}

/**
* Event called before interpolation data is set.
*/
static get BEFORE_INTERPOLATION () {
return 'BEFORE_INTERPOLATION';
}

/**
* Event called after interpolation data is set.
*/
static get AFTER_INTERPOLATION () {
return 'AFTER_INTERPOLATION';
}

/**
* Event name for stage size changing.
* @const {string}
Expand Down
4 changes: 4 additions & 0 deletions src/engine/tw-interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const interpolate = (runtime, time) => {
continue;
}

runtime.emit(runtime.constructor.BEFORE_INTERPOLATION, target);

const drawableID = target.drawableID;

// Position interpolation.
Expand Down Expand Up @@ -137,6 +139,8 @@ const interpolate = (runtime, time) => {
renderer.updateDrawableDirectionScale(drawableID, direction, scale);
}
}

runtime.emit(runtime.constructor.AFTER_INTERPOLATION, target);
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ class VirtualMachine extends EventEmitter {
this.runtime.on(Runtime.INTERPOLATION_CHANGED, framerate => {
this.emit(Runtime.INTERPOLATION_CHANGED, framerate);
});
this.runtime.on(Runtime.BEFORE_INTERPOLATION, target => {
this.emit(Runtime.BEFORE_INTERPOLATION, target);
});
this.runtime.on(Runtime.AFTER_INTERPOLATION, target => {
this.emit(Runtime.AFTER_INTERPOLATION, target);
});
this.runtime.on(Runtime.STAGE_SIZE_CHANGED, (width, height) => {
this.emit(Runtime.STAGE_SIZE_CHANGED, width, height);
});
Expand Down

0 comments on commit b25579a

Please sign in to comment.