Easing test

This commit is contained in:
2026-05-05 22:24:25 -05:00
parent 6da02b25fa
commit 3695b10e4b
7 changed files with 470 additions and 16 deletions
+17 -16
View File
@@ -1,31 +1,32 @@
var PHASE_LEFT = 0;
var PHASE_RIGHT = 1;
var SPEED = 3.0;
var DURATION = 2.0;
function MoveCubeCutscene(params) {
Cutscene.call(this);
this.cube = params.cube;
this.phase = PHASE_LEFT;
this.timer = 0.0;
var startX = this.cube.position.position.x;
this.animLeft = new Animation([
{ time: 0.0, value: startX, easing: Easing.outQuad },
{ time: DURATION, value: startX - SPEED * DURATION }
]);
this.animRight = new Animation([
{ time: 0.0, value: startX - SPEED * DURATION, easing: Easing.inOutQuad },
{ time: DURATION, value: startX }
]);
}
MoveCubeCutscene.prototype = Object.create(Cutscene.prototype);
MoveCubeCutscene.prototype.constructor = MoveCubeCutscene;
MoveCubeCutscene.prototype.update = function() {
this.timer += TIME.delta;
if(this.phase === PHASE_LEFT) {
this.cube.position.position.x -= SPEED * TIME.delta;
if(this.timer >= DURATION) {
this.phase = PHASE_RIGHT;
this.timer = 0.0;
}
} else if(this.phase === PHASE_RIGHT) {
this.cube.position.position.x += SPEED * TIME.delta;
if(this.timer >= DURATION) {
if(!this.animLeft.complete) {
this.cube.position.position.x = this.animLeft.update(TIME.delta);
} else {
this.cube.position.position.x = this.animRight.update(TIME.delta);
if(this.animRight.complete) {
Cutscene.finish();
}
}