diff --git a/CHANGELOG.md b/CHANGELOG.md index 0faf0f335..0bc6b3226 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -133,18 +133,18 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added `easing` option to `moveTo(...)` - Added new option bag style input to actions with durations in milliseconds instead of speed ```typescript - player.actions.rotateTo({angleRadians: angle, durationMs: 1000, rotationType}); - player.actions.moveTo({pos: ex.vec(100, 100), durationMs: 1000}); - player.actions.scaleTo({scale: ex.vec(2, 2), durationMs: 1000}); + player.actions.rotateTo({angleRadians: angle, duration: 1000, rotationType}); + player.actions.moveTo({pos: ex.vec(100, 100), duration: 1000}); + player.actions.scaleTo({scale: ex.vec(2, 2), duration: 1000}); player.actions.repeatForever(ctx => { ctx.curveTo({ controlPoints: [cp1, cp2, dest], - durationMs: 5000, + duration: 5000, mode: 'uniform' }); ctx.curveTo({ controlPoints: [cp2, cp1, start1], - durationMs: 5000, + duration: 5000, mode: 'uniform' }); }); @@ -267,6 +267,7 @@ are doing mtv adjustments during precollision. ### Updates +- Remove units by default from parameters - Perf improve PolygonCollider.contains(...) perf by keeping geometry tests in local space. - Perf improvement to image rendering! with ImageRendererV2! Roughly doubles the performance of image rendering - Perf improvement to retrieving components with `ex.Entity.get()` which widely improves engine performance diff --git a/sandbox/tests/bezier/index.ts b/sandbox/tests/bezier/index.ts index 387e311aa..9ca7fa3c9 100644 --- a/sandbox/tests/bezier/index.ts +++ b/sandbox/tests/bezier/index.ts @@ -147,12 +147,12 @@ actor.onPostUpdate = () => { actor.actions.repeatForever((ctx) => { ctx.curveTo({ controlPoints: [cp1, cp2, dest], - durationMs: 5000, + duration: 5000, mode: 'uniform' }); ctx.curveTo({ controlPoints: [cp2, cp1, start1], - durationMs: 5000, + duration: 5000, mode: 'uniform' }); }); diff --git a/sandbox/tests/flash-shader/index.ts b/sandbox/tests/flash-shader/index.ts index 287ac5425..093de495d 100644 --- a/sandbox/tests/flash-shader/index.ts +++ b/sandbox/tests/flash-shader/index.ts @@ -14,7 +14,7 @@ actor.graphics.use(tex.toSprite()); game.add(actor); -var flash = (actor: ex.Actor, color: ex.Color, durationMs: number) => { +var flash = (actor: ex.Actor, color: ex.Color, duration: number) => { const material = game.graphicsContext.createMaterial({ name: 'flash-material', color, @@ -41,8 +41,8 @@ var flash = (actor: ex.Actor, color: ex.Color, durationMs: number) => { actor.graphics.material = material; ex.coroutine( function* () { - const total = durationMs; - let currentDuration = durationMs; + const total = duration; + let currentDuration = duration; while (currentDuration > 0) { const elapsed = yield; currentDuration -= elapsed; diff --git a/sandbox/tests/rotation/rotation.ts b/sandbox/tests/rotation/rotation.ts index dce7314a3..48e4664d3 100644 --- a/sandbox/tests/rotation/rotation.ts +++ b/sandbox/tests/rotation/rotation.ts @@ -85,7 +85,7 @@ engine.input.pointers.primary.on('down', (e: ex.PointerEvent) => { var vector = new ex.Vector(e.worldPos.x - player.pos.x, e.worldPos.y - player.pos.y); var angle = vector.toAngle(); - player.actions.rotateTo({ angleRadians: angle, durationMs: 1000, rotationType }); + player.actions.rotateTo({ angle: angle, duration: 1000, rotationType }); //console.log('rotating from ' + player.rotation + ' to ' + angle); } }); diff --git a/src/engine/Actions/Action.ts b/src/engine/Actions/Action.ts index b32e91f09..484145e54 100644 --- a/src/engine/Actions/Action.ts +++ b/src/engine/Actions/Action.ts @@ -5,7 +5,7 @@ import { Entity } from '../EntityComponentSystem/Entity'; */ export interface Action { id: number; - update(elapsedMs: number): void; + update(elapsed: number): void; isComplete(entity: Entity): boolean; reset(): void; stop(): void; diff --git a/src/engine/Actions/Action/ActionSequence.ts b/src/engine/Actions/Action/ActionSequence.ts index abf30123c..11909122b 100644 --- a/src/engine/Actions/Action/ActionSequence.ts +++ b/src/engine/Actions/Action/ActionSequence.ts @@ -20,8 +20,8 @@ export class ActionSequence implements Action { this._sequenceBuilder(this._sequenceContext); } - public update(elapsedMs: number): void { - this._actionQueue.update(elapsedMs); + public update(elapsed: number): void { + this._actionQueue.update(elapsed); } public isComplete(): boolean { diff --git a/src/engine/Actions/Action/Blink.ts b/src/engine/Actions/Action/Blink.ts index bdd0f836c..357eaf2c9 100644 --- a/src/engine/Actions/Action/Blink.ts +++ b/src/engine/Actions/Action/Blink.ts @@ -19,7 +19,7 @@ export class Blink implements Action { this._duration = (timeVisible + timeNotVisible) * numBlinks; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._elapsedTime = 0; @@ -29,8 +29,8 @@ export class Blink implements Action { return; } - this._elapsedTime += elapsedMs; - this._totalTime += elapsedMs; + this._elapsedTime += elapsed; + this._totalTime += elapsed; if (this._graphics.isVisible && this._elapsedTime >= this._timeVisible) { this._graphics.isVisible = false; this._elapsedTime = 0; diff --git a/src/engine/Actions/Action/CallMethod.ts b/src/engine/Actions/Action/CallMethod.ts index 7ade64361..7aa996afb 100644 --- a/src/engine/Actions/Action/CallMethod.ts +++ b/src/engine/Actions/Action/CallMethod.ts @@ -8,7 +8,7 @@ export class CallMethod implements Action { this._method = method; } - public update(elapsedMs: number) { + public update(elapsed: number) { this._method(); this._hasBeenCalled = true; } diff --git a/src/engine/Actions/Action/CurveBy.ts b/src/engine/Actions/Action/CurveBy.ts index 12b11a967..f7555c153 100644 --- a/src/engine/Actions/Action/CurveBy.ts +++ b/src/engine/Actions/Action/CurveBy.ts @@ -10,7 +10,7 @@ export interface CurveByOptions { /** * Total duration for the action to run */ - durationMs: number; + duration: number; /** * Dynamic mode will speed up/slow down depending on the curve * @@ -51,12 +51,12 @@ export class CurveBy implements Action { controlPoints: [vec(0, 0), ...options.controlPoints], quality: options.quality }); - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._mode = options.mode ?? this._mode; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._curve.setControlPoint(0, this._tx.globalPos); this._curve.setControlPoint(1, this._curve.controlPoints[1].add(this._tx.globalPos)); @@ -64,7 +64,7 @@ export class CurveBy implements Action { this._curve.setControlPoint(3, this._curve.controlPoints[3].add(this._tx.globalPos)); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); if (this._mode === 'dynamic') { this._tx.pos = this._curve.getPoint(t); diff --git a/src/engine/Actions/Action/CurveTo.ts b/src/engine/Actions/Action/CurveTo.ts index 73a5ae81c..83c64ffbf 100644 --- a/src/engine/Actions/Action/CurveTo.ts +++ b/src/engine/Actions/Action/CurveTo.ts @@ -12,7 +12,7 @@ export interface CurveToOptions { /** * Total duration for the action to run */ - durationMs: number; + duration: number; /** * Dynamic mode will speed up/slow down depending on the curve * @@ -52,17 +52,17 @@ export class CurveTo implements Action { controlPoints: [vec(0, 0), ...options.controlPoints], quality: options.quality }); - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._mode = options.mode ?? this._mode; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._curve.setControlPoint(0, this._tx.globalPos.clone()); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); if (this._mode === 'dynamic') { this._tx.pos = this._curve.getPoint(t); diff --git a/src/engine/Actions/Action/Delay.ts b/src/engine/Actions/Action/Delay.ts index f8a0ed49d..b7da59d17 100644 --- a/src/engine/Actions/Action/Delay.ts +++ b/src/engine/Actions/Action/Delay.ts @@ -6,16 +6,16 @@ export class Delay implements Action { private _delay: number; private _started: boolean = false; private _stopped = false; - constructor(durationMs: number) { - this._delay = durationMs; + constructor(duration: number) { + this._delay = duration; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; } - this._elapsedTime += elapsedMs; + this._elapsedTime += elapsed; } isComplete(): boolean { diff --git a/src/engine/Actions/Action/Die.ts b/src/engine/Actions/Action/Die.ts index f8dea88c3..d343a6dd6 100644 --- a/src/engine/Actions/Action/Die.ts +++ b/src/engine/Actions/Action/Die.ts @@ -11,7 +11,7 @@ export class Die implements Action { this._entity = entity; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { this._entity.get(ActionsComponent).clearActions(); this._entity.kill(); this._stopped = true; diff --git a/src/engine/Actions/Action/EaseBy.ts b/src/engine/Actions/Action/EaseBy.ts index de57362ca..e60512c50 100644 --- a/src/engine/Actions/Action/EaseBy.ts +++ b/src/engine/Actions/Action/EaseBy.ts @@ -5,7 +5,7 @@ import { vec, Vector } from '../../Math/vector'; import { Action, nextActionId } from '../Action'; /** - * @deprecated use moveBy({offset: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use moveBy({offset: Vector, duration: number, easing: EasingFunction}) */ export class EaseBy implements Action { id = nextActionId(); @@ -36,14 +36,14 @@ export class EaseBy implements Action { this._lerpEnd = this._lerpStart.add(this._offset); } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._initialized) { this._initialize(); this._initialized = true; } // Need to update lerp time first, otherwise the first update will always be zero - this._currentLerpTime += elapsedMs; + this._currentLerpTime += elapsed; let newX = this._tx.pos.x; let newY = this._tx.pos.y; if (this._currentLerpTime < this._lerpDuration) { @@ -63,7 +63,7 @@ export class EaseBy implements Action { newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration); } // Given the lerp position figure out the velocity in pixels per second - this._motion.vel = vec((newX - this._tx.pos.x) / (elapsedMs / 1000), (newY - this._tx.pos.y) / (elapsedMs / 1000)); + this._motion.vel = vec((newX - this._tx.pos.x) / (elapsed / 1000), (newY - this._tx.pos.y) / (elapsed / 1000)); } else { this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y); this._motion.vel = Vector.Zero; diff --git a/src/engine/Actions/Action/EaseTo.ts b/src/engine/Actions/Action/EaseTo.ts index 26537d404..c8247b32f 100644 --- a/src/engine/Actions/Action/EaseTo.ts +++ b/src/engine/Actions/Action/EaseTo.ts @@ -5,7 +5,7 @@ import { vec, Vector } from '../../Math/vector'; import { Action, nextActionId } from '../Action'; /** - * @deprecated use moveTo({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use moveTo({pos: Vector, duration: number, easing: EasingFunction}) */ export class EaseTo implements Action { id = nextActionId(); @@ -34,14 +34,14 @@ export class EaseTo implements Action { this._currentLerpTime = 0; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._initialized) { this._initialize(); this._initialized = true; } // Need to update lerp time first, otherwise the first update will always be zero - this._currentLerpTime += elapsedMs; + this._currentLerpTime += elapsed; let newX = this._tx.pos.x; let newY = this._tx.pos.y; if (this._currentLerpTime < this._lerpDuration) { @@ -61,7 +61,7 @@ export class EaseTo implements Action { newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration); } // Given the lerp position figure out the velocity in pixels per second - this._motion.vel = vec((newX - this._tx.pos.x) / (elapsedMs / 1000), (newY - this._tx.pos.y) / (elapsedMs / 1000)); + this._motion.vel = vec((newX - this._tx.pos.x) / (elapsed / 1000), (newY - this._tx.pos.y) / (elapsed / 1000)); } else { this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y); this._motion.vel = Vector.Zero; diff --git a/src/engine/Actions/Action/Fade.ts b/src/engine/Actions/Action/Fade.ts index 96007d338..0f336cb90 100644 --- a/src/engine/Actions/Action/Fade.ts +++ b/src/engine/Actions/Action/Fade.ts @@ -14,13 +14,13 @@ export class Fade implements Action { private _started = false; private _stopped = false; - constructor(entity: Entity, endOpacity: number, durationMs: number) { + constructor(entity: Entity, endOpacity: number, duration: number) { this._graphics = entity.get(GraphicsComponent); this._endOpacity = endOpacity; - this._remainingTime = this._originalTime = durationMs; + this._remainingTime = this._originalTime = duration; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._graphics) { return; } @@ -38,11 +38,10 @@ export class Fade implements Action { } if (this._remainingTime > 0) { - this._graphics.opacity += - (this._multiplier * (Math.abs(this._graphics.opacity - this._endOpacity) * elapsedMs)) / this._remainingTime; + this._graphics.opacity += (this._multiplier * (Math.abs(this._graphics.opacity - this._endOpacity) * elapsed)) / this._remainingTime; } - this._remainingTime -= elapsedMs; + this._remainingTime -= elapsed; if (this.isComplete()) { this._graphics.opacity = this._endOpacity; diff --git a/src/engine/Actions/Action/Flash.ts b/src/engine/Actions/Action/Flash.ts index 5610c15a8..366eebc93 100644 --- a/src/engine/Actions/Action/Flash.ts +++ b/src/engine/Actions/Action/Flash.ts @@ -17,9 +17,9 @@ export class Flash implements Action { private _total: number = 0; private _currentDuration: number = 0; - constructor(entity: Entity, color: Color, durationMs: number = 1000) { + constructor(entity: Entity, color: Color, duration: number = 1000) { this._graphics = entity.get(GraphicsComponent); - this._duration = durationMs; + this._duration = duration; this._entity = entity; this._material = entity.scene?.engine.graphicsContext.createMaterial({ name: 'flash-material', @@ -40,10 +40,10 @@ export class Flash implements Action { color.rgb = color.rgb * color.a; }` }) as Material; - this._total = durationMs; + this._total = duration; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._total = this._duration; @@ -54,7 +54,7 @@ export class Flash implements Action { return; } - this._currentDuration -= elapsedMs; + this._currentDuration -= elapsed; if (this._graphics) { this._material?.update((shader: Shader) => { diff --git a/src/engine/Actions/Action/Follow.ts b/src/engine/Actions/Action/Follow.ts index 63468bc6b..2c3258204 100644 --- a/src/engine/Actions/Action/Follow.ts +++ b/src/engine/Actions/Action/Follow.ts @@ -33,7 +33,7 @@ export class Follow implements Action { this._speed = 0; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._distanceBetween = this._current.distance(this._end); diff --git a/src/engine/Actions/Action/Meet.ts b/src/engine/Actions/Action/Meet.ts index 79e78c1b8..2aa99e9ca 100644 --- a/src/engine/Actions/Action/Meet.ts +++ b/src/engine/Actions/Action/Meet.ts @@ -35,7 +35,7 @@ export class Meet implements Action { } } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._distanceBetween = this._current.distance(this._end); diff --git a/src/engine/Actions/Action/MoveBy.ts b/src/engine/Actions/Action/MoveBy.ts index 8ea176a3d..9cec638a1 100644 --- a/src/engine/Actions/Action/MoveBy.ts +++ b/src/engine/Actions/Action/MoveBy.ts @@ -9,7 +9,7 @@ import { Action, nextActionId } from '../Action'; export interface MoveByOptions { offset: Vector; - durationMs: number; + duration: number; easing?: EasingFunction; } @@ -17,7 +17,7 @@ export interface MoveByOptions { * */ export function isMoveByOptions(x: any): x is MoveByOptions { - return x.offset instanceof Vector && typeof x.durationMs === 'number'; + return x.offset instanceof Vector && typeof x.duration === 'number'; } export class MoveByWithOptions implements Action { @@ -43,22 +43,22 @@ export class MoveByWithOptions implements Action { if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only MoveBy on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._start = this._tx.pos.clone(); this._end = this._start.add(this._offset); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const currentPos = this._tx.pos; const newPosX = this._easing(t, this._start.x, this._end.x, 1); const newPosY = this._easing(t, this._start.y, this._end.y, 1); - const velX = (newPosX - currentPos.x) / (elapsedMs / 1000); - const velY = (newPosY - currentPos.y) / (elapsedMs / 1000); + const velX = (newPosX - currentPos.x) / (elapsed / 1000); + const velY = (newPosY - currentPos.y) / (elapsed / 1000); this._motion.vel.x = velX; this._motion.vel.y = velY; @@ -113,7 +113,7 @@ export class MoveBy implements Action { } } - public update(elapsedMs: number) { + public update(elapsed: number) { if (!this._started) { this._started = true; this._start = new Vector(this._tx.pos.x, this._tx.pos.y); diff --git a/src/engine/Actions/Action/MoveTo.ts b/src/engine/Actions/Action/MoveTo.ts index fb163937c..d97e2d56c 100644 --- a/src/engine/Actions/Action/MoveTo.ts +++ b/src/engine/Actions/Action/MoveTo.ts @@ -8,7 +8,7 @@ import { Action, nextActionId } from '../Action'; export interface MoveToOptions { pos: Vector; - durationMs: number; + duration: number; easing?: EasingFunction; } @@ -16,7 +16,7 @@ export interface MoveToOptions { * */ export function isMoveToOptions(x: any): x is MoveToOptions { - return x.pos instanceof Vector && typeof x.durationMs === 'number'; + return x.pos instanceof Vector && typeof x.duration === 'number'; } export class MoveToWithOptions implements Action { @@ -41,21 +41,21 @@ export class MoveToWithOptions implements Action { if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only moveTo on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._start = this._tx.pos.clone(); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const currentPos = this._tx.pos; const newPosX = this._easing(t, this._start.x, this._end.x, 1); const newPosY = this._easing(t, this._start.y, this._end.y, 1); - const velX = (newPosX - currentPos.x) / (elapsedMs / 1000); - const velY = (newPosY - currentPos.y) / (elapsedMs / 1000); + const velX = (newPosX - currentPos.x) / (elapsed / 1000); + const velY = (newPosY - currentPos.y) / (elapsed / 1000); this._motion.vel.x = velX; this._motion.vel.y = velY; @@ -106,7 +106,7 @@ export class MoveTo implements Action { this._speed = speed; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._start = new Vector(this._tx.pos.x, this._tx.pos.y); diff --git a/src/engine/Actions/Action/ParallelActions.ts b/src/engine/Actions/Action/ParallelActions.ts index 1be23fedc..13ead8b59 100644 --- a/src/engine/Actions/Action/ParallelActions.ts +++ b/src/engine/Actions/Action/ParallelActions.ts @@ -12,9 +12,9 @@ export class ParallelActions implements Action { this._actions = parallelActions; } - update(elapsedMs: number): void { + update(elapsed: number): void { for (let i = 0; i < this._actions.length; i++) { - this._actions[i].update(elapsedMs); + this._actions[i].update(elapsed); } } isComplete(entity: Entity): boolean { diff --git a/src/engine/Actions/Action/Repeat.ts b/src/engine/Actions/Action/Repeat.ts index faf7c5f7f..486816809 100644 --- a/src/engine/Actions/Action/Repeat.ts +++ b/src/engine/Actions/Action/Repeat.ts @@ -23,13 +23,13 @@ export class Repeat implements Action { this._repeat--; // current execution is the first repeat } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (this._actionQueue.isComplete()) { this._actionQueue.clearActions(); this._repeatBuilder(this._repeatContext); this._repeat--; } - this._actionQueue.update(elapsedMs); + this._actionQueue.update(elapsed); } public isComplete(): boolean { diff --git a/src/engine/Actions/Action/RepeatForever.ts b/src/engine/Actions/Action/RepeatForever.ts index 29f78a62f..d00ab0628 100644 --- a/src/engine/Actions/Action/RepeatForever.ts +++ b/src/engine/Actions/Action/RepeatForever.ts @@ -23,7 +23,7 @@ export class RepeatForever implements Action { this._repeatBuilder(this._repeatContext); } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (this._stopped) { return; } @@ -33,7 +33,7 @@ export class RepeatForever implements Action { this._repeatBuilder(this._repeatContext); } - this._actionQueue.update(elapsedMs); + this._actionQueue.update(elapsed); } public isComplete(): boolean { diff --git a/src/engine/Actions/Action/RotateBy.ts b/src/engine/Actions/Action/RotateBy.ts index 57e8716ba..f76f09a2e 100644 --- a/src/engine/Actions/Action/RotateBy.ts +++ b/src/engine/Actions/Action/RotateBy.ts @@ -14,7 +14,7 @@ export interface RotateByOptions { /** * Duration to take in milliseconds */ - durationMs: number; + duration: number; /** * Optionally provide type of rotation, default is RotationType.ShortestPath */ @@ -25,7 +25,7 @@ export interface RotateByOptions { * */ export function isRotateByOptions(x: any): x is RotateByOptions { - return typeof x.angleRadiansOffset === 'number' && typeof x.durationMs === 'number'; + return typeof x.angleRadiansOffset === 'number' && typeof x.duration === 'number'; } export class RotateByWithOptions implements Action { @@ -50,22 +50,22 @@ export class RotateByWithOptions implements Action { if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only RotateBy on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._rotationType = options.rotationType ?? RotationType.ShortestPath; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._startAngle = this._tx.rotation; this._endAngle = canonicalizeAngle(this._startAngle + this._offset); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const newAngle = lerpAngle(this._startAngle, this._endAngle, this._rotationType, t); const currentAngle = this._tx.rotation; - const rx = (newAngle - currentAngle) / (elapsedMs / 1000); + const rx = (newAngle - currentAngle) / (elapsed / 1000); this._motion.angularVelocity = rx; if (this.isComplete()) { @@ -118,7 +118,7 @@ export class RotateBy implements Action { this._rotationType = rotationType || RotationType.ShortestPath; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._start = this._tx.rotation; @@ -174,7 +174,7 @@ export class RotateBy implements Action { } this._motion.angularVelocity = this._direction * this._speed; - this._currentNonCannonAngle += this._direction * this._speed * (elapsedMs / 1000); + this._currentNonCannonAngle += this._direction * this._speed * (elapsed / 1000); if (this.isComplete()) { this._tx.rotation = this._end; diff --git a/src/engine/Actions/Action/RotateTo.ts b/src/engine/Actions/Action/RotateTo.ts index 3d9e45471..bc36b490a 100644 --- a/src/engine/Actions/Action/RotateTo.ts +++ b/src/engine/Actions/Action/RotateTo.ts @@ -10,11 +10,11 @@ export interface RotateToOptions { /** * Absolute angle to rotate to in radians */ - angleRadians: number; + angle: number; /** * Duration to take in milliseconds */ - durationMs: number; + duration: number; /** * Optionally provide type of rotation, default is RotationType.ShortestPath */ @@ -25,7 +25,7 @@ export interface RotateToOptions { * */ export function isRotateToOptions(x: any): x is RotateToOptions { - return typeof x.angleRadians === 'number' && typeof x.durationMs === 'number'; + return typeof x.angle === 'number' && typeof x.duration === 'number'; } export class RotateToWithOptions implements Action { @@ -43,27 +43,27 @@ export class RotateToWithOptions implements Action { public entity: Entity, options: RotateToOptions ) { - this._endAngle = options.angleRadians; + this._endAngle = options.angle; this._tx = entity.get(TransformComponent); this._motion = entity.get(MotionComponent); if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only RotateTo on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._rotationType = options.rotationType ?? RotationType.ShortestPath; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._startAngle = this._tx.rotation; this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const newAngle = lerpAngle(this._startAngle, this._endAngle, this._rotationType, t); const currentAngle = this._tx.rotation; - const rx = (newAngle - currentAngle) / (elapsedMs / 1000); + const rx = (newAngle - currentAngle) / (elapsed / 1000); this._motion.angularVelocity = rx; if (this.isComplete(this.entity)) { @@ -106,15 +106,15 @@ export class RotateTo implements Action { private _currentNonCannonAngle!: number; private _started = false; private _stopped = false; - constructor(entity: Entity, angleRadians: number, speed: number, rotationType?: RotationType) { + constructor(entity: Entity, angle: number, speed: number, rotationType?: RotationType) { this._tx = entity.get(TransformComponent); this._motion = entity.get(MotionComponent); - this._end = angleRadians; + this._end = angle; this._speed = speed; this._rotationType = rotationType || RotationType.ShortestPath; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._start = this._tx.rotation; @@ -168,7 +168,7 @@ export class RotateTo implements Action { } this._motion.angularVelocity = this._direction * this._speed; - this._currentNonCannonAngle += this._direction * this._speed * (elapsedMs / 1000); + this._currentNonCannonAngle += this._direction * this._speed * (elapsed / 1000); if (this.isComplete()) { this._tx.rotation = this._end; diff --git a/src/engine/Actions/Action/ScaleBy.ts b/src/engine/Actions/Action/ScaleBy.ts index 6832563e7..04a67c8f9 100644 --- a/src/engine/Actions/Action/ScaleBy.ts +++ b/src/engine/Actions/Action/ScaleBy.ts @@ -13,14 +13,14 @@ export interface ScaleByOptions { /** * Duration to take in milliseconds */ - durationMs: number; + duration: number; } /** * */ export function isScaleByOptions(x: any): x is ScaleByOptions { - return typeof x.scaleOffset === 'object' && typeof x.durationMs === 'number'; + return typeof x.scaleOffset === 'object' && typeof x.duration === 'number'; } export class ScaleByWithOptions implements Action { @@ -44,20 +44,20 @@ export class ScaleByWithOptions implements Action { if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only ScaleBy on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._startScale = this._tx.scale; this._endScale = this._startScale.add(this._scaleOffset); this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const newScale = lerpVector(this._startScale, this._endScale, t); const currentScale = this._tx.scale; - const sx = newScale.sub(currentScale).scale(1 / (elapsedMs / 1000)); + const sx = newScale.sub(currentScale).scale(1 / (elapsed / 1000)); this._motion.scaleFactor = sx; if (this.isComplete()) { @@ -106,7 +106,7 @@ export class ScaleBy implements Action { this._speedX = this._speedY = speed; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._startScale = this._tx.scale.clone(); diff --git a/src/engine/Actions/Action/ScaleTo.ts b/src/engine/Actions/Action/ScaleTo.ts index fbafd8676..050c9fdc4 100644 --- a/src/engine/Actions/Action/ScaleTo.ts +++ b/src/engine/Actions/Action/ScaleTo.ts @@ -13,14 +13,14 @@ export interface ScaleToOptions { /** * Duration to take in milliseconds */ - durationMs: number; + duration: number; } /** * */ export function isScaleToOptions(x: any): x is ScaleToOptions { - return typeof x.scale === 'object' && typeof x.durationMs === 'number'; + return typeof x.scale === 'object' && typeof x.duration === 'number'; } export class ScaleToWithOptions implements Action { @@ -43,20 +43,20 @@ export class ScaleToWithOptions implements Action { if (!this._tx) { throw new Error(`Entity ${entity.name} has no TransformComponent, can only ScaleTo on Entities with TransformComponents.`); } - this._durationMs = options.durationMs; + this._durationMs = options.duration; this._currentMs = this._durationMs; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._started) { this._startScale = this._tx.scale; this._started = true; } - this._currentMs -= elapsedMs; + this._currentMs -= elapsed; const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const newScale = lerpVector(this._startScale, this._endScale, t); const currentScale = this._tx.scale; - const sx = newScale.sub(currentScale).scale(1 / (elapsedMs / 1000)); + const sx = newScale.sub(currentScale).scale(1 / (elapsed / 1000)); this._motion.scaleFactor = sx; if (this.isComplete()) { @@ -106,7 +106,7 @@ export class ScaleTo implements Action { this._speedY = speedY; } - public update(elapsedMs: number): void { + public update(elapsed: number): void { if (!this._started) { this._started = true; this._startX = this._tx.scale.x; diff --git a/src/engine/Actions/ActionContext.ts b/src/engine/Actions/ActionContext.ts index c67509da5..6635294e5 100644 --- a/src/engine/Actions/ActionContext.ts +++ b/src/engine/Actions/ActionContext.ts @@ -46,8 +46,8 @@ export class ActionContext { return this._queue; } - public update(elapsedMs: number) { - this._queue.update(elapsedMs); + public update(elapsed: number) { + this._queue.update(elapsed); } /** @@ -88,22 +88,22 @@ export class ActionContext { * specified duration using a given {@apilink EasingFunctions} and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. * @param pos The x,y vector location to move the actor to - * @param durationMs The time it should take the actor to move to the new location in milliseconds + * @param duration The time it should take the actor to move to the new location in milliseconds * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeTo(pos: Vector, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeTo(pos: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; /** * This method will move an actor to the specified `x` and `y` position over the * specified duration using a given {@apilink EasingFunctions} and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. * @param x The x location to move the actor to * @param y The y location to move the actor to - * @param durationMs The time it should take the actor to move to the new location in milliseconds + * @param duration The time it should take the actor to move to the new location in milliseconds * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeTo(x: number, y: number, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeTo(x: number, y: number, duration: number, easingFcn?: EasingFunction): ActionContext; public easeTo(...args: any[]): ActionContext { let x = 0; let y = 0; @@ -129,20 +129,20 @@ export class ActionContext { * This method will move an actor by a specified vector offset relative to the current position given * a duration and a {@apilink EasingFunction}. This method is part of the actor 'Action' fluent API allowing action chaining. * @param offset Vector offset relative to the current position - * @param durationMs The duration in milliseconds + * @param duration The duration in milliseconds * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveBy({offset: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveBy({offset: Vector, duration: number, easing: EasingFunction}) */ - public easeBy(offset: Vector, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeBy(offset: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; /** * This method will move an actor by a specified x and y offset relative to the current position given * a duration and a {@apilink EasingFunction}. This method is part of the actor 'Action' fluent API allowing action chaining. * @param offset Vector offset relative to the current position - * @param durationMs The duration in milliseconds + * @param duration The duration in milliseconds * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveBy({offset: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveBy({offset: Vector, duration: number, easing: EasingFunction}) */ - public easeBy(offsetX: number, offsetY: number, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeBy(offsetX: number, offsetY: number, duration: number, easingFcn?: EasingFunction): ActionContext; public easeBy(...args: any[]): ActionContext { let offsetX = 0; let offsetY = 0; @@ -256,11 +256,11 @@ export class ActionContext { * This method will rotate an actor to the specified angle at the speed * specified (in radians per second) and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. - * @param angleRadians The angle to rotate to in radians + * @param angle The angle to rotate to in radians * @param speed The angular velocity of the rotation specified in radians per second * @param rotationType The {@apilink RotationType} to use for this rotation */ - public rotateTo(angleRadians: number, speed: number, rotationType?: RotationType): ActionContext; + public rotateTo(angle: number, speed: number, rotationType?: RotationType): ActionContext; public rotateTo(angleRadiansOrOptions: number | RotateToOptions, speed?: number, rotationType?: RotationType): ActionContext { if (typeof angleRadiansOrOptions === 'number' && typeof speed === 'number') { this._queue.add(new RotateTo(this._entity, angleRadiansOrOptions, speed, rotationType)); @@ -422,20 +422,20 @@ export class ActionContext { * to the provided value by a specified time (in milliseconds). This method is * part of the actor 'Action' fluent API allowing action chaining. * @param opacity The ending opacity - * @param durationMs The time it should take to fade the actor (in milliseconds) + * @param duration The time it should take to fade the actor (in milliseconds) */ - public fade(opacity: number, durationMs: number): ActionContext { - this._queue.add(new Fade(this._entity, opacity, durationMs)); + public fade(opacity: number, duration: number): ActionContext { + this._queue.add(new Fade(this._entity, opacity, duration)); return this; } /** * This will cause an actor to flash a specific color for a period of time * @param color - * @param durationMs The duration in milliseconds + * @param duration The duration in milliseconds */ - public flash(color: Color, durationMs: number = 1000) { - this._queue.add(new Flash(this._entity, color, durationMs)); + public flash(color: Color, duration: number = 1000) { + this._queue.add(new Flash(this._entity, color, duration)); return this; } @@ -443,10 +443,10 @@ export class ActionContext { * This method will delay the next action from executing for a certain * amount of time (in milliseconds). This method is part of the actor * 'Action' fluent API allowing action chaining. - * @param durationMs The amount of time to delay the next action in the queue from executing in milliseconds + * @param duration The amount of time to delay the next action in the queue from executing in milliseconds */ - public delay(durationMs: number): ActionContext { - this._queue.add(new Delay(durationMs)); + public delay(duration: number): ActionContext { + this._queue.add(new Delay(duration)); return this; } diff --git a/src/engine/Actions/ActionQueue.ts b/src/engine/Actions/ActionQueue.ts index e13af01a0..500ff9abc 100644 --- a/src/engine/Actions/ActionQueue.ts +++ b/src/engine/Actions/ActionQueue.ts @@ -95,16 +95,16 @@ export class ActionQueue { /** * Update the queue which updates actions and handles completing actions - * @param elapsedMs + * @param elapsed */ - public update(elapsedMs: number) { + public update(elapsed: number) { if (this._actions.length > 0) { if (this._currentAction !== this._actions[0]) { this._currentAction = this._actions[0]; this._entity.emit('actionstart', new ActionStartEvent(this._currentAction, this._entity)); } - this._currentAction.update(elapsedMs); + this._currentAction.update(elapsed); if (this._currentAction.isComplete(this._entity)) { this._entity.emit('actioncomplete', new ActionCompleteEvent(this._currentAction, this._entity)); diff --git a/src/engine/Actions/ActionsComponent.ts b/src/engine/Actions/ActionsComponent.ts index 7544e9139..1c37972b7 100644 --- a/src/engine/Actions/ActionsComponent.ts +++ b/src/engine/Actions/ActionsComponent.ts @@ -60,10 +60,10 @@ export class ActionsComponent extends Component implements ActionContextMethods /** * Updates the internal action context, performing action and moving through the internal queue - * @param elapsedMs + * @param elapsed */ - public update(elapsedMs: number): void { - return this._ctx?.update(elapsedMs); + public update(elapsed: number): void { + return this._ctx?.update(elapsed); } /** @@ -96,22 +96,22 @@ export class ActionsComponent extends Component implements ActionContextMethods * specified duration using a given {@apilink EasingFunctions} and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. * @param pos The x,y vector location to move the actor to - * @param durationMs The time it should take the actor to move to the new location in milliseconds + * @param duration The time it should take the actor to move to the new location in milliseconds * @param easingFcn Use {@apilink EasingFunctions} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeTo(pos: Vector, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeTo(pos: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; /** * This method will move an actor to the specified `x` and `y` position over the * specified duration using a given {@apilink EasingFunctions} and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. * @param x The x location to move the actor to * @param y The y location to move the actor to - * @param durationMs The time it should take the actor to move to the new location in milliseconds + * @param duration The time it should take the actor to move to the new location in milliseconds * @param easingFcn Use {@apilink EasingFunctions} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeTo(x: number, y: number, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeTo(x: number, y: number, duration: number, easingFcn?: EasingFunction): ActionContext; public easeTo(...args: any[]): ActionContext { return this._getCtx().easeTo.apply(this._ctx, args as any); } @@ -119,20 +119,20 @@ export class ActionsComponent extends Component implements ActionContextMethods /** * * @param offset - * @param durationMs + * @param duration * @param easingFcn - * @deprecated use new moveBy({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveBy({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeBy(offset: Vector, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeBy(offset: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; /** * * @param offsetX * @param offsetY - * @param durationMs + * @param duration * @param easingFcn - * @deprecated use new moveBy({pos: Vector, durationMs: number, easing: EasingFunction}) + * @deprecated use new moveBy({pos: Vector, duration: number, easing: EasingFunction}) */ - public easeBy(offsetX: number, offsetY: number, durationMs: number, easingFcn?: EasingFunction): ActionContext; + public easeBy(offsetX: number, offsetY: number, duration: number, easingFcn?: EasingFunction): ActionContext; public easeBy(...args: any[]): ActionContext { return this._getCtx().easeBy.apply(this._ctx, args as any); } @@ -203,13 +203,13 @@ export class ActionsComponent extends Component implements ActionContextMethods * This method will rotate an actor to the specified angle at the speed * specified (in radians per second) and return back the actor. This * method is part of the actor 'Action' fluent API allowing action chaining. - * @param angleRadians The angle to rotate to in radians + * @param angle The angle to rotate to in radians * @param speed The angular velocity of the rotation specified in radians per second * @param rotationType The {@apilink RotationType} to use for this rotation */ - public rotateTo(angleRadians: number, speed: number, rotationType?: RotationType): ActionContext; - public rotateTo(angleRadians: number | RotateToOptions, speed?: number, rotationType?: RotationType): ActionContext { - return this._getCtx().rotateTo.apply(this._ctx, [angleRadians, speed, rotationType] as any); + public rotateTo(angle: number, speed: number, rotationType?: RotationType): ActionContext; + public rotateTo(angle: number | RotateToOptions, speed?: number, rotationType?: RotationType): ActionContext { + return this._getCtx().rotateTo.apply(this._ctx, [angle, speed, rotationType] as any); } /** @@ -313,29 +313,29 @@ export class ActionsComponent extends Component implements ActionContextMethods * to the provided value by a specified time (in milliseconds). This method is * part of the actor 'Action' fluent API allowing action chaining. * @param opacity The ending opacity - * @param durationMs The time it should take to fade the actor (in milliseconds) + * @param duration The time it should take to fade the actor (in milliseconds) */ - public fade(opacity: number, durationMs: number): ActionContext { - return this._getCtx().fade(opacity, durationMs); + public fade(opacity: number, duration: number): ActionContext { + return this._getCtx().fade(opacity, duration); } /** * This will cause an actor to flash a specific color for a period of time * @param color - * @param durationMs The duration in milliseconds + * @param duration The duration in milliseconds */ - public flash(color: Color, durationMs: number = 1000) { - return this._getCtx().flash(color, durationMs); + public flash(color: Color, duration: number = 1000) { + return this._getCtx().flash(color, duration); } /** * This method will delay the next action from executing for a certain * amount of time (in milliseconds). This method is part of the actor * 'Action' fluent API allowing action chaining. - * @param durationMs The amount of time to delay the next action in the queue from executing in milliseconds + * @param duration The amount of time to delay the next action in the queue from executing in milliseconds */ - public delay(durationMs: number): ActionContext { - return this._getCtx().delay(durationMs); + public delay(duration: number): ActionContext { + return this._getCtx().delay(duration); } /** diff --git a/src/engine/Actions/ActionsSystem.ts b/src/engine/Actions/ActionsSystem.ts index 8ebde3c38..bf5ceb819 100644 --- a/src/engine/Actions/ActionsSystem.ts +++ b/src/engine/Actions/ActionsSystem.ts @@ -22,10 +22,10 @@ export class ActionsSystem extends System { } }); } - update(elapsedMs: number): void { + update(elapsed: number): void { for (let i = 0; i < this._actions.length; i++) { const action = this._actions[i]; - action.update(elapsedMs); + action.update(elapsed); } } } diff --git a/src/engine/Actor.ts b/src/engine/Actor.ts index 67927f014..4a8c0806a 100644 --- a/src/engine/Actor.ts +++ b/src/engine/Actor.ts @@ -973,13 +973,13 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * Called by the Engine, updates the state of the actor * @internal * @param engine The reference to the current game engine - * @param elapsedMs The time elapsed since the last update in milliseconds + * @param elapsed The time elapsed since the last update in milliseconds */ - public update(engine: Engine, elapsedMs: number) { + public update(engine: Engine, elapsed: number) { this._initialize(engine); this._add(engine); - this._preupdate(engine, elapsedMs); - this._postupdate(engine, elapsedMs); + this._preupdate(engine, elapsed); + this._postupdate(engine, elapsed); this._remove(engine); } @@ -987,8 +987,10 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})` * * `onPreUpdate` is called directly before an actor is updated. + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds */ - public onPreUpdate(engine: Engine, elapsedMs: number): void { + public onPreUpdate(engine: Engine, elapsed: number): void { // Override me } @@ -996,8 +998,10 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * Safe to override onPostUpdate lifecycle event handler. Synonymous with `.on('postupdate', (evt) =>{...})` * * `onPostUpdate` is called directly after an actor is updated. + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds */ - public onPostUpdate(engine: Engine, elapsedMs: number): void { + public onPostUpdate(engine: Engine, elapsed: number): void { // Override me } @@ -1050,22 +1054,26 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * It is not recommended that internal excalibur methods be overridden, do so at your own risk. * * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds * @internal */ - public _preupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('preupdate', new PreUpdateEvent(engine, elapsedMs, this)); - this.onPreUpdate(engine, elapsedMs); + public _preupdate(engine: Engine, elapsed: number): void { + this.events.emit('preupdate', new PreUpdateEvent(engine, elapsed, this)); + this.onPreUpdate(engine, elapsed); } /** * It is not recommended that internal excalibur methods be overridden, do so at your own risk. * * Internal _preupdate handler for {@apilink onPostUpdate} lifecycle event + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds * @internal */ - public _postupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('postupdate', new PostUpdateEvent(engine, elapsedMs, this)); - this.onPostUpdate(engine, elapsedMs); + public _postupdate(engine: Engine, elapsed: number): void { + this.events.emit('postupdate', new PostUpdateEvent(engine, elapsed, this)); + this.onPostUpdate(engine, elapsed); } // endregion diff --git a/src/engine/Camera.ts b/src/engine/Camera.ts index d84745218..f8aad8d06 100644 --- a/src/engine/Camera.ts +++ b/src/engine/Camera.ts @@ -29,9 +29,9 @@ export interface CameraStrategy { * @param target The target object to apply this camera strategy (if any) * @param camera The current camera implementation in excalibur running the game * @param engine The current engine running the game - * @param elapsedMs The elapsed time in milliseconds since the last frame + * @param elapsed The elapsed time in milliseconds since the last frame */ - action: (target: T, camera: Camera, engine: Engine, elapsedMs: number) => Vector; + action: (target: T, camera: Camera, engine: Engine, elapsed: number) => Vector; } /** @@ -102,7 +102,7 @@ export enum Axis { */ export class LockCameraToActorStrategy implements CameraStrategy { constructor(public target: Actor) {} - public action = (target: Actor, camera: Camera, engine: Engine, elapsedMs: number) => { + public action = (target: Actor, camera: Camera, engine: Engine, elapsed: number) => { const center = target.center; return center; }; @@ -116,7 +116,7 @@ export class LockCameraToActorAxisStrategy implements CameraStrategy { public target: Actor, public axis: Axis ) {} - public action = (target: Actor, cam: Camera, _eng: Engine, elapsedMs: number) => { + public action = (target: Actor, cam: Camera, _eng: Engine, elapsed: number) => { const center = target.center; const currentFocus = cam.getFocus(); if (this.axis === Axis.X) { @@ -144,7 +144,7 @@ export class ElasticToActorStrategy implements CameraStrategy { public cameraElasticity: number, public cameraFriction: number ) {} - public action = (target: Actor, cam: Camera, _eng: Engine, elapsedMs: number) => { + public action = (target: Actor, cam: Camera, _eng: Engine, elapsed: number) => { const position = target.center; let focus = cam.getFocus(); let cameraVel = cam.vel.clone(); @@ -178,7 +178,7 @@ export class RadiusAroundActorStrategy implements CameraStrategy { public target: Actor, public radius: number ) {} - public action = (target: Actor, cam: Camera, _eng: Engine, elapsedMs: number) => { + public action = (target: Actor, cam: Camera, _eng: Engine, elapsed: number) => { const position = target.center; const focus = cam.getFocus(); @@ -211,7 +211,7 @@ export class LimitCameraBoundsStrategy implements CameraStrategy { constructor(public target: BoundingBox) {} - public action = (target: BoundingBox, cam: Camera, _eng: Engine, elapsedMs: number) => { + public action = (target: BoundingBox, cam: Camera, _eng: Engine, elapsed: number) => { const focus = cam.getFocus(); if (!this.boundSizeChecked) { @@ -583,19 +583,23 @@ export class Camera implements CanUpdate, CanInitialize { * It is not recommended that internal excalibur methods be overridden, do so at your own risk. * * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds * @internal */ - public _preupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('preupdate', new PreUpdateEvent(engine, elapsedMs, this)); - this.onPreUpdate(engine, elapsedMs); + public _preupdate(engine: Engine, elapsed: number): void { + this.events.emit('preupdate', new PreUpdateEvent(engine, elapsed, this)); + this.onPreUpdate(engine, elapsed); } /** * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})` * * `onPreUpdate` is called directly before a scene is updated. + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds */ - public onPreUpdate(engine: Engine, elapsedMs: number): void { + public onPreUpdate(engine: Engine, elapsed: number): void { // Overridable } @@ -603,19 +607,23 @@ export class Camera implements CanUpdate, CanInitialize { * It is not recommended that internal excalibur methods be overridden, do so at your own risk. * * Internal _preupdate handler for {@apilink onPostUpdate} lifecycle event + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds * @internal */ - public _postupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('postupdate', new PostUpdateEvent(engine, elapsedMs, this)); - this.onPostUpdate(engine, elapsedMs); + public _postupdate(engine: Engine, elapsed: number): void { + this.events.emit('postupdate', new PostUpdateEvent(engine, elapsed, this)); + this.onPostUpdate(engine, elapsed); } /** * Safe to override onPostUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})` * * `onPostUpdate` is called directly after a scene is updated. + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds */ - public onPostUpdate(engine: Engine, elapsedMs: number): void { + public onPostUpdate(engine: Engine, elapsed: number): void { // Overridable } @@ -705,9 +713,9 @@ export class Camera implements CanUpdate, CanInitialize { this.events.off(eventName, handler); } - public runStrategies(engine: Engine, elapsedMs: number) { + public runStrategies(engine: Engine, elapsed: number) { for (const s of this._cameraStrategies) { - this.pos = s.action.call(s, s.target, this, engine, elapsedMs); + this.pos = s.action.call(s, s.target, this, engine, elapsed); } } @@ -721,19 +729,19 @@ export class Camera implements CanUpdate, CanInitialize { ); } - public update(engine: Engine, elapsedMs: number) { + public update(engine: Engine, elapsed: number) { this._initialize(engine); - this._preupdate(engine, elapsedMs); + this._preupdate(engine, elapsed); this.pos.clone(this._oldPos); // Update placements based on linear algebra - this.pos = this.pos.add(this.vel.scale(elapsedMs / 1000)); - this.zoom += (this.dz * elapsedMs) / 1000; + this.pos = this.pos.add(this.vel.scale(elapsed / 1000)); + this.zoom += (this.dz * elapsed) / 1000; - this.vel = this.vel.add(this.acc.scale(elapsedMs / 1000)); - this.dz += (this.az * elapsedMs) / 1000; + this.vel = this.vel.add(this.acc.scale(elapsed / 1000)); + this.dz += (this.az * elapsed) / 1000; - this.rotation += (this.angularVelocity * elapsedMs) / 1000; + this.rotation += (this.angularVelocity * elapsed) / 1000; if (this._isZooming) { if (this._currentZoomTime < this._zoomDuration) { @@ -741,7 +749,7 @@ export class Camera implements CanUpdate, CanInitialize { const newZoom = zoomEasing(this._currentZoomTime, this._zoomStart, this._zoomEnd, this._zoomDuration); this.zoom = newZoom; - this._currentZoomTime += elapsedMs; + this._currentZoomTime += elapsed; } else { this._isZooming = false; this.zoom = this._zoomEnd; @@ -758,7 +766,7 @@ export class Camera implements CanUpdate, CanInitialize { this.pos = lerpPoint; - this._currentLerpTime += elapsedMs; + this._currentLerpTime += elapsed; } else { this.pos = this._lerpEnd; const end = this._lerpEnd.clone(); @@ -781,19 +789,19 @@ export class Camera implements CanUpdate, CanInitialize { this._xShake = 0; this._yShake = 0; } else { - this._elapsedShakeTime += elapsedMs; + this._elapsedShakeTime += elapsed; this._xShake = ((Math.random() * this._shakeMagnitudeX) | 0) + 1; this._yShake = ((Math.random() * this._shakeMagnitudeY) | 0) + 1; } - this.runStrategies(engine, elapsedMs); + this.runStrategies(engine, elapsed); this.updateViewport(); // It's important to update the camera after strategies // This prevents jitter this.updateTransform(this.pos); - this._postupdate(engine, elapsedMs); + this._postupdate(engine, elapsed); this._posChanged = false; } diff --git a/src/engine/Collision/CollisionSystem.ts b/src/engine/Collision/CollisionSystem.ts index 53bafda97..7d27c3d67 100644 --- a/src/engine/Collision/CollisionSystem.ts +++ b/src/engine/Collision/CollisionSystem.ts @@ -74,7 +74,7 @@ export class CollisionSystem extends System { this._engine = scene.engine; } - update(elapsedMs: number): void { + update(elapsed: number): void { if (!this._physics.config.enabled) { return; } @@ -105,10 +105,10 @@ export class CollisionSystem extends System { // Update the spatial partitioning data structures // TODO if collider invalid it will break the processor // TODO rename "update" to something more specific - this._processor.update(colliders, elapsedMs); + this._processor.update(colliders, elapsed); // Run broadphase on all colliders and locates potential collisions - let pairs = this._processor.broadphase(colliders, elapsedMs); + let pairs = this._processor.broadphase(colliders, elapsed); this._currentFrameContacts.clear(); @@ -122,7 +122,7 @@ export class CollisionSystem extends System { for (let step = 0; step < substep; step++) { if (step > 0) { // first step is run by the MotionSystem when configured, so skip - this._motionSystem.update(elapsedMs); + this._motionSystem.update(elapsed); } // Re-use pairs from previous collision if (contacts.length) { diff --git a/src/engine/Collision/Detection/CollisionProcessor.ts b/src/engine/Collision/Detection/CollisionProcessor.ts index 22b411164..f6220e55c 100644 --- a/src/engine/Collision/Detection/CollisionProcessor.ts +++ b/src/engine/Collision/Detection/CollisionProcessor.ts @@ -50,7 +50,7 @@ export interface CollisionProcessor { /** * Detect potential collision pairs given a list of colliders */ - broadphase(targets: Collider[], elapsedMs: number, stats?: FrameStats): Pair[]; + broadphase(targets: Collider[], elapsed: number, stats?: FrameStats): Pair[]; /** * Identify actual collisions from those pairs, and calculate collision impulse @@ -60,10 +60,10 @@ export interface CollisionProcessor { /** * Update the internal structures to track colliders */ - update(targets: Collider[], elapsedMs: number): number; + update(targets: Collider[], elapsed: number): number; /** * Draw any debug information */ - debug(ex: ExcaliburGraphicsContext, elapsedMs: number): void; + debug(ex: ExcaliburGraphicsContext, elapsed: number): void; } diff --git a/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts b/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts index 96a59cdd7..85ee04f44 100644 --- a/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts +++ b/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts @@ -173,8 +173,8 @@ export class DynamicTreeCollisionProcessor implements CollisionProcessor { /** * Detects potential collision pairs in a broadphase approach with the dynamic AABB tree strategy */ - public broadphase(targets: Collider[], elapsedMs: number, stats?: FrameStats): Pair[] { - const seconds = elapsedMs / 1000; + public broadphase(targets: Collider[], elapsed: number, stats?: FrameStats): Pair[] { + const seconds = elapsed / 1000; // Retrieve the list of potential colliders, exclude killed, prevented, and self const potentialColliders = targets.filter((other) => { diff --git a/src/engine/Collision/Detection/SparseHashGrid.ts b/src/engine/Collision/Detection/SparseHashGrid.ts index ce513d2ae..ac396ceeb 100644 --- a/src/engine/Collision/Detection/SparseHashGrid.ts +++ b/src/engine/Collision/Detection/SparseHashGrid.ts @@ -273,7 +273,7 @@ export class SparseHashGrid, elapsedMs: number): void { + postupdate(engine: Scene, elapsed: number): void { if (this._engine.isDebug) { this._graphicsContext.save(); if (this._camera) { diff --git a/src/engine/Director/Director.ts b/src/engine/Director/Director.ts index b72a7ce42..51cf05d65 100644 --- a/src/engine/Director/Director.ts +++ b/src/engine/Director/Director.ts @@ -407,7 +407,7 @@ export class Director { * @param destinationScene * @param options */ - async goto(destinationScene: TKnownScenes | string, options?: GoToOptions) { + async goToScene(destinationScene: TKnownScenes | string, options?: GoToOptions) { const maybeDest = this.getSceneInstance(destinationScene); if (!maybeDest) { this._logger.warn(`Scene ${destinationScene} does not exist! Check the name, are you sure you added it?`); diff --git a/src/engine/Director/Transition.ts b/src/engine/Director/Transition.ts index e8caa52f6..a2f131d68 100644 --- a/src/engine/Director/Transition.ts +++ b/src/engine/Director/Transition.ts @@ -113,14 +113,14 @@ export class Transition extends Entity { * * **WARNING BE SURE** to call `super.updateTransition()` if overriding in your own custom implementation * @param engine - * @param elapsedMs + * @param elapsed */ - public updateTransition(engine: Engine, elapsedMs: number): void { + public updateTransition(engine: Engine, elapsed: number): void { if (this.complete) { return; } - this._currentDistance += clamp(elapsedMs / this.duration, 0, 1); + this._currentDistance += clamp(elapsed / this.duration, 0, 1); if (this._currentDistance >= 1) { this._currentDistance = 1; } diff --git a/src/engine/Engine.ts b/src/engine/Engine.ts index 93f0cb23e..3d9eaadd7 100644 --- a/src/engine/Engine.ts +++ b/src/engine/Engine.ts @@ -1426,7 +1426,7 @@ O|===|* >________________>\n\ */ public async goToScene(destinationScene: WithRoot, options?: GoToOptions): Promise { await this.scope(async () => { - await this.director.goto(destinationScene, options); + await this.director.goToScene(destinationScene, options); }); } @@ -1507,12 +1507,12 @@ O|===|* >________________>\n\ /** * Updates the entire state of the game - * @param elapsedMs Number of milliseconds elapsed since the last update. + * @param elapsed Number of milliseconds elapsed since the last update. */ - private _update(elapsedMs: number) { + private _update(elapsed: number) { if (this._isLoading) { // suspend updates until loading is finished - this._loader?.onUpdate(this, elapsedMs); + this._loader?.onUpdate(this, elapsed); // Update input listeners this.input.update(); return; @@ -1520,17 +1520,17 @@ O|===|* >________________>\n\ // Publish preupdate events this.clock.__runScheduledCbs('preupdate'); - this._preupdate(elapsedMs); + this._preupdate(elapsed); // process engine level events - this.currentScene.update(this, elapsedMs); + this.currentScene.update(this, elapsed); // Update graphics postprocessors - this.graphicsContext.updatePostProcessors(elapsedMs); + this.graphicsContext.updatePostProcessors(elapsed); // Publish update event this.clock.__runScheduledCbs('postupdate'); - this._postupdate(elapsedMs); + this._postupdate(elapsed); // Update input listeners this.input.update(); @@ -1539,38 +1539,48 @@ O|===|* >________________>\n\ /** * @internal */ - public _preupdate(elapsedMs: number) { - this.emit('preupdate', new PreUpdateEvent(this, elapsedMs, this)); - this.onPreUpdate(this, elapsedMs); + public _preupdate(elapsed: number) { + this.emit('preupdate', new PreUpdateEvent(this, elapsed, this)); + this.onPreUpdate(this, elapsed); } - public onPreUpdate(engine: Engine, elapsedMs: number) { + /** + * Safe to override method + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds + */ + public onPreUpdate(engine: Engine, elapsed: number) { // Override me } /** * @internal */ - public _postupdate(elapsedMs: number) { - this.emit('postupdate', new PostUpdateEvent(this, elapsedMs, this)); - this.onPostUpdate(this, elapsedMs); + public _postupdate(elapsed: number) { + this.emit('postupdate', new PostUpdateEvent(this, elapsed, this)); + this.onPostUpdate(this, elapsed); } - public onPostUpdate(engine: Engine, elapsedMs: number) { + /** + * Safe to override method + * @param engine The reference to the current game engine + * @param elapsed The time elapsed since the last update in milliseconds + */ + public onPostUpdate(engine: Engine, elapsed: number) { // Override me } /** * Draws the entire game - * @param elapsedMs Number of milliseconds elapsed since the last draw. + * @param elapsed Number of milliseconds elapsed since the last draw. */ - private _draw(elapsedMs: number) { + private _draw(elapsed: number) { // Use scene background color if present, fallback to engine this.graphicsContext.backgroundColor = this.currentScene.backgroundColor ?? this.backgroundColor; this.graphicsContext.beginDrawLifecycle(); this.graphicsContext.clear(); this.clock.__runScheduledCbs('predraw'); - this._predraw(this.graphicsContext, elapsedMs); + this._predraw(this.graphicsContext, elapsed); // Drawing nothing else while loading if (this._isLoading) { @@ -1583,10 +1593,10 @@ O|===|* >________________>\n\ return; } - this.currentScene.draw(this.graphicsContext, elapsedMs); + this.currentScene.draw(this.graphicsContext, elapsed); this.clock.__runScheduledCbs('postdraw'); - this._postdraw(this.graphicsContext, elapsedMs); + this._postdraw(this.graphicsContext, elapsed); // Flush any pending drawings this.graphicsContext.flush(); @@ -1598,24 +1608,34 @@ O|===|* >________________>\n\ /** * @internal */ - public _predraw(ctx: ExcaliburGraphicsContext, elapsedMs: number) { - this.emit('predraw', new PreDrawEvent(ctx, elapsedMs, this)); - this.onPreDraw(ctx, elapsedMs); + public _predraw(ctx: ExcaliburGraphicsContext, elapsed: number) { + this.emit('predraw', new PreDrawEvent(ctx, elapsed, this)); + this.onPreDraw(ctx, elapsed); } - public onPreDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number) { + /** + * Safe to override method to hook into pre draw + * @param ctx {@link ExcaliburGraphicsContext} for drawing + * @param elapsed Number of milliseconds elapsed since the last draw. + */ + public onPreDraw(ctx: ExcaliburGraphicsContext, elapsed: number) { // Override me } /** * @internal */ - public _postdraw(ctx: ExcaliburGraphicsContext, elapsedMs: number) { - this.emit('postdraw', new PostDrawEvent(ctx, elapsedMs, this)); - this.onPostDraw(ctx, elapsedMs); + public _postdraw(ctx: ExcaliburGraphicsContext, elapsed: number) { + this.emit('postdraw', new PostDrawEvent(ctx, elapsed, this)); + this.onPostDraw(ctx, elapsed); } - public onPostDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number) { + /** + * Safe to override method to hook into pre draw + * @param ctx {@link ExcaliburGraphicsContext} for drawing + * @param elapsed Number of milliseconds elapsed since the last draw. + */ + public onPostDraw(ctx: ExcaliburGraphicsContext, elapsed: number) { // Override me } diff --git a/src/engine/EntityComponentSystem/Entity.ts b/src/engine/EntityComponentSystem/Entity.ts index 65a8092b4..967494db0 100644 --- a/src/engine/EntityComponentSystem/Entity.ts +++ b/src/engine/EntityComponentSystem/Entity.ts @@ -583,9 +583,9 @@ export class Entity implements OnIniti * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event * @internal */ - public _preupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('preupdate', new PreUpdateEvent(engine, elapsedMs, this)); - this.onPreUpdate(engine, elapsedMs); + public _preupdate(engine: Engine, elapsed: number): void { + this.events.emit('preupdate', new PreUpdateEvent(engine, elapsed, this)); + this.onPreUpdate(engine, elapsed); } /** @@ -594,9 +594,9 @@ export class Entity implements OnIniti * Internal _preupdate handler for {@apilink onPostUpdate} lifecycle event * @internal */ - public _postupdate(engine: Engine, elapsedMs: number): void { - this.events.emit('postupdate', new PostUpdateEvent(engine, elapsedMs, this)); - this.onPostUpdate(engine, elapsedMs); + public _postupdate(engine: Engine, elapsed: number): void { + this.events.emit('postupdate', new PostUpdateEvent(engine, elapsed, this)); + this.onPostUpdate(engine, elapsed); } /** @@ -634,7 +634,7 @@ export class Entity implements OnIniti * * `onPreUpdate` is called directly before an entity is updated. */ - public onPreUpdate(engine: Engine, elapsedMs: number): void { + public onPreUpdate(engine: Engine, elapsed: number): void { // Override me } @@ -643,7 +643,7 @@ export class Entity implements OnIniti * * `onPostUpdate` is called directly after an entity is updated. */ - public onPostUpdate(engine: Engine, elapsedMs: number): void { + public onPostUpdate(engine: Engine, elapsed: number): void { // Override me } @@ -652,16 +652,16 @@ export class Entity implements OnIniti * Entity update lifecycle, called internally * @internal * @param engine - * @param elapsedMs + * @param elapsed */ - public update(engine: Engine, elapsedMs: number): void { + public update(engine: Engine, elapsed: number): void { this._initialize(engine); this._add(engine); - this._preupdate(engine, elapsedMs); + this._preupdate(engine, elapsed); for (const child of this.children) { - child.update(engine, elapsedMs); + child.update(engine, elapsed); } - this._postupdate(engine, elapsedMs); + this._postupdate(engine, elapsed); this._remove(engine); } diff --git a/src/engine/EntityComponentSystem/System.ts b/src/engine/EntityComponentSystem/System.ts index 8819ab961..41d3215a6 100644 --- a/src/engine/EntityComponentSystem/System.ts +++ b/src/engine/EntityComponentSystem/System.ts @@ -23,9 +23,14 @@ export enum SystemType { * * ```typescript * class MySystem extends System { - * public readonly types = ['a', 'b'] as const; + * static priority = SystemPriority.Lowest; * public readonly systemType = SystemType.Update; - * public update(elapsedMs) { + * public query: Query; + * constructor(public world: World) { + * super(); + * this.query = this.world.query([TransformComponent]); + * } + * public update(elapsed: number) { * ... * } * } @@ -52,21 +57,21 @@ export abstract class System { /** * Update all entities that match this system's types - * @param elapsedMs Time in milliseconds + * @param elapsed Time in milliseconds */ - abstract update(elapsedMs: number): void; + abstract update(elapsed: number): void; /** * Optionally run a preupdate before the system processes matching entities * @param scene - * @param elapsedMs Time in milliseconds since the last frame + * @param elapsed Time in milliseconds since the last frame */ - preupdate?(scene: Scene, elapsedMs: number): void; + preupdate?(scene: Scene, elapsed: number): void; /** * Optionally run a postupdate after the system processes matching entities * @param scene - * @param elapsedMs Time in milliseconds since the last frame + * @param elapsed Time in milliseconds since the last frame */ - postupdate?(scene: Scene, elapsedMs: number): void; + postupdate?(scene: Scene, elapsed: number): void; } diff --git a/src/engine/EntityComponentSystem/SystemManager.ts b/src/engine/EntityComponentSystem/SystemManager.ts index 4189496d0..3d57a8db5 100644 --- a/src/engine/EntityComponentSystem/SystemManager.ts +++ b/src/engine/EntityComponentSystem/SystemManager.ts @@ -83,23 +83,23 @@ export class SystemManager { * Updates all systems * @param type whether this is an update or draw system * @param scene context reference - * @param elapsedMs time in milliseconds + * @param elapsed time in milliseconds */ - public updateSystems(type: SystemType, scene: Scene, elapsedMs: number) { + public updateSystems(type: SystemType, scene: Scene, elapsed: number) { const systems = this.systems.filter((s) => s.systemType === type); for (const s of systems) { if (s.preupdate) { - s.preupdate(scene, elapsedMs); + s.preupdate(scene, elapsed); } } for (const s of systems) { - s.update(elapsedMs); + s.update(elapsed); } for (const s of systems) { if (s.postupdate) { - s.postupdate(scene, elapsedMs); + s.postupdate(scene, elapsed); } } } diff --git a/src/engine/EntityComponentSystem/World.ts b/src/engine/EntityComponentSystem/World.ts index 3ff8c15cf..d3b65f2e6 100644 --- a/src/engine/EntityComponentSystem/World.ts +++ b/src/engine/EntityComponentSystem/World.ts @@ -37,11 +37,11 @@ export class World { /** * Update systems by type and time elapsed in milliseconds */ - update(type: SystemType, elapsedMs: number) { + update(type: SystemType, elapsed: number) { if (type === SystemType.Update) { - this.entityManager.updateEntities(this.scene, elapsedMs); + this.entityManager.updateEntities(this.scene, elapsed); } - this.systemManager.updateSystems(type, this.scene, elapsedMs); + this.systemManager.updateSystems(type, this.scene, elapsed); this.entityManager.findEntitiesForRemoval(); this.entityManager.processComponentRemovals(); this.entityManager.processEntityRemovals(); diff --git a/src/engine/Events.ts b/src/engine/Events.ts index 3e5d95b82..315beca8f 100644 --- a/src/engine/Events.ts +++ b/src/engine/Events.ts @@ -259,7 +259,7 @@ export class GameStopEvent extends GameEvent { export class PreDrawEvent extends GameEvent { constructor( public ctx: ExcaliburGraphicsContext, - public elapsedMs: number, + public elapsed: number, public self: Entity | Scene | Engine | TileMap ) { super(); @@ -275,7 +275,7 @@ export class PreDrawEvent extends GameEvent { export class PostDrawEvent extends GameEvent { constructor( public ctx: ExcaliburGraphicsContext, - public elapsedMs: number, + public elapsed: number, public self: Entity | Scene | Engine | TileMap ) { super(); @@ -292,7 +292,7 @@ export class PostDrawEvent extends GameEvent export class PreTransformDrawEvent extends GameEvent { constructor( public ctx: ExcaliburGraphicsContext, - public elapsedMs: number, + public elapsed: number, public self: Entity ) { super(); @@ -308,7 +308,7 @@ export class PreTransformDrawEvent extends GameEvent { export class PostTransformDrawEvent extends GameEvent { constructor( public ctx: ExcaliburGraphicsContext, - public elapsedMs: number, + public elapsed: number, public self: Entity ) { super(); @@ -348,7 +348,7 @@ export class PostDebugDrawEvent extends GameEvent extends GameEvent { constructor( public engine: Engine, - public elapsedMs: number, + public elapsed: number, public self: T ) { super(); @@ -362,7 +362,7 @@ export class PreUpdateEvent extends GameEvent export class PostUpdateEvent extends GameEvent { constructor( public engine: Engine, - public elapsedMs: number, + public elapsed: number, public self: T ) { super(); diff --git a/src/engine/Graphics/Animation.ts b/src/engine/Graphics/Animation.ts index 9286d0759..28703a472 100644 --- a/src/engine/Graphics/Animation.ts +++ b/src/engine/Graphics/Animation.ts @@ -8,10 +8,10 @@ import { EventEmitter } from '../EventEmitter'; export interface HasTick { /** * - * @param elapsedMilliseconds The amount of real world time in milliseconds that has elapsed that must be updated in the animation + * @param elapsed The amount of real world time in milliseconds that has elapsed that must be updated in the animation * @param idempotencyToken Optional idempotencyToken prevents a ticking animation from updating twice per frame */ - tick(elapsedMilliseconds: number, idempotencyToken?: number): void; + tick(elapsed: number, idempotencyToken?: number): void; } export enum AnimationDirection { @@ -121,8 +121,13 @@ export interface FromSpriteSheetOptions { frameCoordinates: { x: number; y: number; duration?: number; options?: GetSpriteOptions }[]; /** * Optionally specify a default duration for frames in milliseconds + * @deprecated use `durationPerFrame` */ durationPerFrameMs?: number; + /** + * Optionally specify a default duration for frames in milliseconds + */ + durationPerFrame?: number; /** * Optionally set a positive speed multiplier on the animation. * @@ -212,13 +217,13 @@ export class Animation extends Graphic implements HasTick { * ``` * @param spriteSheet ex.SpriteSheet * @param spriteSheetIndex 0 based index from left to right, top down (row major order) of the ex.SpriteSheet - * @param durationPerFrameMs duration per frame in milliseconds + * @param durationPerFrame duration per frame in milliseconds * @param strategy Optional strategy, default AnimationStrategy.Loop */ public static fromSpriteSheet( spriteSheet: SpriteSheet, spriteSheetIndex: number[], - durationPerFrameMs: number, + durationPerFrame: number, strategy: AnimationStrategy = AnimationStrategy.Loop ): Animation { const maxIndex = spriteSheet.sprites.length - 1; @@ -233,7 +238,7 @@ export class Animation extends Graphic implements HasTick { .filter((_, index) => spriteSheetIndex.indexOf(index) > -1) .map((f) => ({ graphic: f, - duration: durationPerFrameMs + duration: durationPerFrame })), strategy: strategy }); @@ -261,8 +266,8 @@ export class Animation extends Graphic implements HasTick { * @returns Animation */ public static fromSpriteSheetCoordinates(options: FromSpriteSheetOptions): Animation { - const { spriteSheet, frameCoordinates, durationPerFrameMs, speed, strategy, reverse } = options; - const defaultDuration = durationPerFrameMs ?? 100; + const { spriteSheet, frameCoordinates, durationPerFrame, durationPerFrameMs, speed, strategy, reverse } = options; + const defaultDuration = durationPerFrame ?? durationPerFrameMs ?? 100; const frames: Frame[] = []; for (const coord of frameCoordinates) { const { x, y, duration, options } = coord; diff --git a/src/engine/Graphics/Context/ExcaliburGraphicsContext.ts b/src/engine/Graphics/Context/ExcaliburGraphicsContext.ts index 1a6c13ff9..9a375d4bb 100644 --- a/src/engine/Graphics/Context/ExcaliburGraphicsContext.ts +++ b/src/engine/Graphics/Context/ExcaliburGraphicsContext.ts @@ -357,10 +357,10 @@ export interface ExcaliburGraphicsContext { * Updates all post processors in the graphics context * * Called internally by Excalibur - * @param elapsedMs + * @param elapsed * @internal */ - updatePostProcessors(elapsedMs: number): void; + updatePostProcessors(elapsed: number): void; /** * Gets or sets the material to be used in the current context's drawings diff --git a/src/engine/Graphics/Context/ExcaliburGraphicsContext2DCanvas.ts b/src/engine/Graphics/Context/ExcaliburGraphicsContext2DCanvas.ts index 4babf1bfc..45e6656e9 100644 --- a/src/engine/Graphics/Context/ExcaliburGraphicsContext2DCanvas.ts +++ b/src/engine/Graphics/Context/ExcaliburGraphicsContext2DCanvas.ts @@ -329,7 +329,7 @@ export class ExcaliburGraphicsContext2DCanvas implements ExcaliburGraphicsContex // pass } - public updatePostProcessors(elapsedMs: number) { + public updatePostProcessors(elapsed: number) { // pass } diff --git a/src/engine/Graphics/Context/ExcaliburGraphicsContextWebGL.ts b/src/engine/Graphics/Context/ExcaliburGraphicsContextWebGL.ts index bf656d8d7..36c00d8e1 100644 --- a/src/engine/Graphics/Context/ExcaliburGraphicsContextWebGL.ts +++ b/src/engine/Graphics/Context/ExcaliburGraphicsContextWebGL.ts @@ -611,25 +611,25 @@ export class ExcaliburGraphicsContextWebGL implements ExcaliburGraphicsContext { } private _totalPostProcessorTime = 0; - public updatePostProcessors(elapsedMs: number) { + public updatePostProcessors(elapsed: number) { for (const postprocessor of this._postprocessors) { const shader = postprocessor.getShader(); shader.use(); const uniforms = shader.getUniforms(); - this._totalPostProcessorTime += elapsedMs; + this._totalPostProcessorTime += elapsed; if (uniforms.find((u) => u.name === 'u_time_ms')) { shader.setUniformFloat('u_time_ms', this._totalPostProcessorTime); } if (uniforms.find((u) => u.name === 'u_elapsed_ms')) { - shader.setUniformFloat('u_elapsed_ms', elapsedMs); + shader.setUniformFloat('u_elapsed_ms', elapsed); } if (uniforms.find((u) => u.name === 'u_resolution')) { shader.setUniformFloatVector('u_resolution', vec(this.width, this.height)); } if (postprocessor.onUpdate) { - postprocessor.onUpdate(elapsedMs); + postprocessor.onUpdate(elapsed); } } } diff --git a/src/engine/Graphics/Context/particle-renderer/particle-renderer.ts b/src/engine/Graphics/Context/particle-renderer/particle-renderer.ts index 0ebda2bc9..a74718882 100644 --- a/src/engine/Graphics/Context/particle-renderer/particle-renderer.ts +++ b/src/engine/Graphics/Context/particle-renderer/particle-renderer.ts @@ -60,7 +60,7 @@ export class ParticleRenderer implements RendererPlugin { return texture; } - draw(renderer: GpuParticleRenderer, elapsedMs: number): void { + draw(renderer: GpuParticleRenderer, elapsed: number): void { const gl = this._gl; this._shader.use(); @@ -70,7 +70,7 @@ export class ParticleRenderer implements RendererPlugin { this._shader.setUniformBoolean('fade', renderer.particle.fade ? true : false); this._shader.setUniformBoolean('useTexture', renderer.particle.graphic ? true : false); this._shader.setUniformFloat('maxLifeMs', renderer.particle.life ?? 2000); - this._shader.setUniformFloat('deltaMs', elapsedMs); + this._shader.setUniformFloat('deltaMs', elapsed); this._shader.setUniformFloatVector('gravity', renderer.particle.acc ?? vec(0, 0)); this._shader.setUniformFloatColor('beginColor', renderer.particle.beginColor ?? Color.Transparent); this._shader.setUniformFloatColor('endColor', renderer.particle.endColor ?? Color.Transparent); diff --git a/src/engine/Graphics/GraphicsComponent.ts b/src/engine/Graphics/GraphicsComponent.ts index f2060be04..f51c3e0bc 100644 --- a/src/engine/Graphics/GraphicsComponent.ts +++ b/src/engine/Graphics/GraphicsComponent.ts @@ -93,22 +93,22 @@ export class GraphicsComponent extends Component { /** * Draws after the entity transform has been applied, but before graphics component graphics have been drawn */ - public onPreDraw?: (ctx: ExcaliburGraphicsContext, elapsedMilliseconds: number) => void; + public onPreDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void; /** * Draws after the entity transform has been applied, and after graphics component graphics has been drawn */ - public onPostDraw?: (ctx: ExcaliburGraphicsContext, elapsedMilliseconds: number) => void; + public onPostDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void; /** * Draws before the entity transform has been applied before any any graphics component drawing */ - public onPreTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsedMilliseconds: number) => void; + public onPreTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void; /** * Draws after the entity transform has been applied, and after all graphics component drawing */ - public onPostTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsedMilliseconds: number) => void; + public onPostTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void; private _color?: Color; /** diff --git a/src/engine/Graphics/GraphicsGroup.ts b/src/engine/Graphics/GraphicsGroup.ts index 430afa8a9..5b12db453 100644 --- a/src/engine/Graphics/GraphicsGroup.ts +++ b/src/engine/Graphics/GraphicsGroup.ts @@ -81,7 +81,7 @@ export class GraphicsGroup extends Graphic implements HasTick { return graphic instanceof Animation || graphic instanceof GraphicsGroup; } - public tick(elapsedMilliseconds: number, idempotencyToken?: number) { + public tick(elapsed: number, idempotencyToken?: number) { for (const member of this.members) { let graphic: Graphic; if (member instanceof Graphic) { @@ -90,7 +90,7 @@ export class GraphicsGroup extends Graphic implements HasTick { graphic = member.graphic; } if (this._isAnimationOrGroup(graphic)) { - graphic.tick(elapsedMilliseconds, idempotencyToken); + graphic.tick(elapsed, idempotencyToken); } } } diff --git a/src/engine/Graphics/GraphicsSystem.ts b/src/engine/Graphics/GraphicsSystem.ts index abee87429..9d04db977 100644 --- a/src/engine/Graphics/GraphicsSystem.ts +++ b/src/engine/Graphics/GraphicsSystem.ts @@ -72,7 +72,7 @@ export class GraphicsSystem extends System { } } - public update(elapsedMs: number): void { + public update(elapsed: number): void { this._token++; let graphics: GraphicsComponent; FontCache.checkAndClearCache(); @@ -100,9 +100,9 @@ export class GraphicsSystem extends System { // Optionally run the onPreTransformDraw graphics lifecycle draw if (graphics.onPreTransformDraw) { - graphics.onPreTransformDraw(this._graphicsContext, elapsedMs); + graphics.onPreTransformDraw(this._graphicsContext, elapsed); } - entity.events.emit('pretransformdraw', new PreTransformDrawEvent(this._graphicsContext, elapsedMs, entity)); + entity.events.emit('pretransformdraw', new PreTransformDrawEvent(this._graphicsContext, elapsed, entity)); // This optionally sets our camera based on the entity coord plan (world vs. screen) if (transform.coordPlane === CoordPlane.Screen) { @@ -115,7 +115,7 @@ export class GraphicsSystem extends System { } // Tick any graphics state (but only once) for animations and graphics groups - graphics.update(elapsedMs, this._token); + graphics.update(elapsed, this._token); // Apply parallax const parallax = entity.get(ParallaxComponent); @@ -138,9 +138,9 @@ export class GraphicsSystem extends System { // Optionally run the onPreDraw graphics lifecycle draw if (graphics.onPreDraw) { - graphics.onPreDraw(this._graphicsContext, elapsedMs); + graphics.onPreDraw(this._graphicsContext, elapsed); } - entity.events.emit('predraw', new PreDrawEvent(this._graphicsContext, elapsedMs, entity)); + entity.events.emit('predraw', new PreDrawEvent(this._graphicsContext, elapsed, entity)); // this._graphicsContext.opacity *= graphics.opacity; this._applyOpacity(entity); @@ -150,9 +150,9 @@ export class GraphicsSystem extends System { // Optionally run the onPostDraw graphics lifecycle draw if (graphics.onPostDraw) { - graphics.onPostDraw(this._graphicsContext, elapsedMs); + graphics.onPostDraw(this._graphicsContext, elapsed); } - entity.events.emit('postdraw', new PostDrawEvent(this._graphicsContext, elapsedMs, entity)); + entity.events.emit('postdraw', new PostDrawEvent(this._graphicsContext, elapsed, entity)); this._graphicsContext.restore(); @@ -166,9 +166,9 @@ export class GraphicsSystem extends System { // Optionally run the onPreTransformDraw graphics lifecycle draw if (graphics.onPostTransformDraw) { - graphics.onPostTransformDraw(this._graphicsContext, elapsedMs); + graphics.onPostTransformDraw(this._graphicsContext, elapsed); } - entity.events.emit('posttransformdraw', new PostTransformDrawEvent(this._graphicsContext, elapsedMs, entity)); + entity.events.emit('posttransformdraw', new PostTransformDrawEvent(this._graphicsContext, elapsed, entity)); } this._graphicsContext.restore(); } diff --git a/src/engine/Graphics/PostProcessor/PostProcessor.ts b/src/engine/Graphics/PostProcessor/PostProcessor.ts index 7174ea4ae..a9edda217 100644 --- a/src/engine/Graphics/PostProcessor/PostProcessor.ts +++ b/src/engine/Graphics/PostProcessor/PostProcessor.ts @@ -25,7 +25,7 @@ export interface PostProcessor { * Use the onUpdate hook to update any uniforms in the postprocessors shader * * The shader has already been bound so there is no need to call shader.use(); - * @param elapsedMs + * @param elapsed */ - onUpdate?(elapsedMs: number): void; + onUpdate?(elapsed: number): void; } diff --git a/src/engine/Interfaces/LifecycleEvents.ts b/src/engine/Interfaces/LifecycleEvents.ts index f46c99c71..91bc938f4 100644 --- a/src/engine/Interfaces/LifecycleEvents.ts +++ b/src/engine/Interfaces/LifecycleEvents.ts @@ -52,7 +52,7 @@ export function hasOnInitialize(a: any): a is OnInitialize { // eslint-disable-next-line @typescript-eslint/naming-convention export interface _preupdate { - _preupdate(engine: Engine, elapsedMs: number): void; + _preupdate(engine: Engine, elapsed: number): void; } /** @@ -63,7 +63,7 @@ export function has_preupdate(a: any): a is _preupdate { } export interface OnPreUpdate { - onPreUpdate(engine: Engine, elapsedMs: number): void; + onPreUpdate(engine: Engine, elapsed: number): void; } /** @@ -75,7 +75,7 @@ export function hasOnPreUpdate(a: any): a is OnPreUpdate { // eslint-disable-next-line @typescript-eslint/naming-convention export interface _postupdate { - _postupdate(engine: Engine, elapsedMs: number): void; + _postupdate(engine: Engine, elapsed: number): void; } /** @@ -86,7 +86,7 @@ export function has_postupdate(a: any): a is _postupdate { } export interface OnPostUpdate { - onPostUpdate(engine: Engine, elapsedMs: number): void; + onPostUpdate(engine: Engine, elapsed: number): void; } /** @@ -187,7 +187,7 @@ export interface CanUpdate { /** * Overridable implementation */ - onPreUpdate(engine: Engine, elapsedMs: number): void; + onPreUpdate(engine: Engine, elapsed: number): void; /** * Event signature @@ -199,7 +199,7 @@ export interface CanUpdate { /** * Overridable implementation */ - onPostUpdate(engine: Engine, elapsedMs: number): void; + onPostUpdate(engine: Engine, elapsed: number): void; /** * Event signatures @@ -213,7 +213,7 @@ export interface OnPreDraw { /** * Overridable implementation */ - onPreDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void; + onPreDraw(ctx: ExcaliburGraphicsContext, elapsed: number): void; /** * Event signatures @@ -227,7 +227,7 @@ export interface OnPostDraw { /** * Overridable implementation */ - onPostDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void; + onPostDraw(ctx: ExcaliburGraphicsContext, elapsed: number): void; /** * Event signatures diff --git a/src/engine/Math/affine-matrix.ts b/src/engine/Math/affine-matrix.ts index 9f389a419..9b0f96af8 100644 --- a/src/engine/Math/affine-matrix.ts +++ b/src/engine/Math/affine-matrix.ts @@ -62,15 +62,15 @@ export class AffineMatrix { } /** - * Creates a brand new rotation matrix with the specified angle - * @param angleRadians + * Creates a brand new rotation matrix with the specified angle in radians + * @param angle */ - public static rotation(angleRadians: number): AffineMatrix { + public static rotation(angle: number): AffineMatrix { const mat = AffineMatrix.identity(); - mat.data[0] = Math.cos(angleRadians); - mat.data[1] = Math.sin(angleRadians); - mat.data[2] = -Math.sin(angleRadians); - mat.data[3] = Math.cos(angleRadians); + mat.data[0] = Math.cos(angle); + mat.data[1] = Math.sin(angle); + mat.data[2] = -Math.sin(angle); + mat.data[3] = Math.cos(angle); return mat; } diff --git a/src/engine/Math/lerp.ts b/src/engine/Math/lerp.ts index 78b3e9e9c..80a4a6da9 100644 --- a/src/engine/Math/lerp.ts +++ b/src/engine/Math/lerp.ts @@ -14,14 +14,14 @@ export function lerp(a: number, b: number, time: number): number { /** * Linear interpolation between angles in radians - * @param startAngleRadians - * @param endAngleRadians + * @param startAngle + * @param endAngle * @param rotationType * @param time */ -export function lerpAngle(startAngleRadians: number, endAngleRadians: number, rotationType: RotationType, time: number): number { - const shortestPathIsPositive = (startAngleRadians - endAngleRadians + TwoPI) % TwoPI >= Math.PI; - const distance1 = Math.abs(endAngleRadians - startAngleRadians); +export function lerpAngle(startAngle: number, endAngle: number, rotationType: RotationType, time: number): number { + const shortestPathIsPositive = (startAngle - endAngle + TwoPI) % TwoPI >= Math.PI; + const distance1 = Math.abs(endAngle - startAngle); const distance2 = TwoPI - distance1; let shortDistance = 0; let longDistance = 0; @@ -54,7 +54,7 @@ export function lerpAngle(startAngleRadians: number, endAngleRadians: number, ro break; } - return startAngleRadians + direction * (distance * time); + return startAngle + direction * (distance * time); } /** diff --git a/src/engine/Math/matrix.ts b/src/engine/Math/matrix.ts index 56a44964a..177e3f972 100644 --- a/src/engine/Math/matrix.ts +++ b/src/engine/Math/matrix.ts @@ -185,15 +185,15 @@ export class Matrix { } /** - * Creates a brand new rotation matrix with the specified angle - * @param angleRadians + * Creates a brand new rotation matrix with the specified angle in radians + * @param angle */ - public static rotation(angleRadians: number): Matrix { + public static rotation(angle: number): Matrix { const mat = Matrix.identity(); - mat.data[0] = Math.cos(angleRadians); - mat.data[4] = -Math.sin(angleRadians); - mat.data[1] = Math.sin(angleRadians); - mat.data[5] = Math.cos(angleRadians); + mat.data[0] = Math.cos(angle); + mat.data[4] = -Math.sin(angle); + mat.data[1] = Math.sin(angle); + mat.data[5] = Math.cos(angle); return mat; } diff --git a/src/engine/Particles/GpuParticleEmitter.ts b/src/engine/Particles/GpuParticleEmitter.ts index a9a994a76..c91d2091b 100644 --- a/src/engine/Particles/GpuParticleEmitter.ts +++ b/src/engine/Particles/GpuParticleEmitter.ts @@ -78,24 +78,24 @@ export class GpuParticleEmitter extends Actor { } private _particlesToEmit = 0; - public update(engine: Engine, elapsedMs: number): void { - super.update(engine, elapsedMs); + public update(engine: Engine, elapsed: number): void { + super.update(engine, elapsed); if (this.isEmitting) { - this._particlesToEmit += this.emitRate * (elapsedMs / 1000); + this._particlesToEmit += this.emitRate * (elapsed / 1000); if (this._particlesToEmit > 1.0) { this.emitParticles(Math.floor(this._particlesToEmit)); this._particlesToEmit = this._particlesToEmit - Math.floor(this._particlesToEmit); } } - this.renderer.update(elapsedMs); + this.renderer.update(elapsed); } public emitParticles(particleCount: number) { this.renderer.emitParticles(particleCount); } - draw(ctx: ExcaliburGraphicsContextWebGL, elapsedMilliseconds: number) { - ctx.draw('ex.particle', this.renderer, elapsedMilliseconds); + draw(ctx: ExcaliburGraphicsContextWebGL, elapsed: number) { + ctx.draw('ex.particle', this.renderer, elapsed); } } diff --git a/src/engine/Particles/GpuParticleRenderer.ts b/src/engine/Particles/GpuParticleRenderer.ts index 9236ddd99..79212bca6 100644 --- a/src/engine/Particles/GpuParticleRenderer.ts +++ b/src/engine/Particles/GpuParticleRenderer.ts @@ -238,10 +238,10 @@ export class GpuParticleRenderer { this._uploadIndex = this._particleIndex % (this.maxParticles * this._numInputFloats); } - update(elapsedMs: number) { + update(elapsed: number) { this._particleLife = this.particle.life ?? this._particleLife; if (this._wrappedLife > 0) { - this._wrappedLife -= elapsedMs; + this._wrappedLife -= elapsed; } else { this._wrappedLife = 0; this._wrappedParticles = 0; @@ -251,7 +251,7 @@ export class GpuParticleRenderer { } for (let i = this._emitted.length - 1; i >= 0; i--) { const particle = this._emitted[i]; - particle[0] -= elapsedMs; + particle[0] -= elapsed; const life = particle[0]; if (life <= 0) { this._emitted.splice(i, 1); diff --git a/src/engine/Particles/ParticleEmitter.ts b/src/engine/Particles/ParticleEmitter.ts index 3b2f35404..703045384 100644 --- a/src/engine/Particles/ParticleEmitter.ts +++ b/src/engine/Particles/ParticleEmitter.ts @@ -160,11 +160,11 @@ export class ParticleEmitter extends Actor { return p; } - public update(engine: Engine, elapsedMs: number) { - super.update(engine, elapsedMs); + public update(engine: Engine, elapsed: number) { + super.update(engine, elapsed); if (this.isEmitting) { - this._particlesToEmit += this.emitRate * (elapsedMs / 1000); + this._particlesToEmit += this.emitRate * (elapsed / 1000); if (this._particlesToEmit > 1.0) { this.emitParticles(Math.floor(this._particlesToEmit)); this._particlesToEmit = this._particlesToEmit - Math.floor(this._particlesToEmit); diff --git a/src/engine/Particles/Particles.ts b/src/engine/Particles/Particles.ts index 528a323c2..4e6dd97dc 100644 --- a/src/engine/Particles/Particles.ts +++ b/src/engine/Particles/Particles.ts @@ -132,8 +132,8 @@ export class Particle extends Entity { } } - public update(engine: Engine, elapsedMs: number) { - this.life = this.life - elapsedMs; + public update(engine: Engine, elapsed: number) { + this.life = this.life - elapsed; if (this.life < 0) { this.kill(); @@ -145,15 +145,15 @@ export class Particle extends Entity { if (this.startSize && this.endSize && this.startSize > 0 && this.endSize > 0) { this.size = clamp( - this.sizeRate * elapsedMs + this.size, + this.sizeRate * elapsed + this.size, Math.min(this.startSize, this.endSize), Math.max(this.startSize, this.endSize) ); } - this._currentColor.r = clamp(this._currentColor.r + this._rRate * elapsedMs, 0, 255); - this._currentColor.g = clamp(this._currentColor.g + this._gRate * elapsedMs, 0, 255); - this._currentColor.b = clamp(this._currentColor.b + this._bRate * elapsedMs, 0, 255); + this._currentColor.r = clamp(this._currentColor.r + this._rRate * elapsed, 0, 255); + this._currentColor.g = clamp(this._currentColor.g + this._gRate * elapsed, 0, 255); + this._currentColor.b = clamp(this._currentColor.b + this._bRate * elapsed, 0, 255); this._currentColor.a = this.graphics.opacity; let accel = this.motion.acc; @@ -162,10 +162,10 @@ export class Particle extends Entity { .sub(this.transform.pos) .normalize() .scale(this.focusAccel || 0) - .scale(elapsedMs / 1000); + .scale(elapsed / 1000); } // Update transform and motion based on Euler linear algebra - EulerIntegrator.integrate(this.transform, this.motion, accel, elapsedMs); + EulerIntegrator.integrate(this.transform, this.motion, accel, elapsed); } } diff --git a/src/engine/Resources/Gif.ts b/src/engine/Resources/Gif.ts index 98f4d8609..a2f274bab 100644 --- a/src/engine/Resources/Gif.ts +++ b/src/engine/Resources/Gif.ts @@ -96,9 +96,9 @@ export class Gif implements Loadable { /** * Transform the GIF into an animation with duration per frame - * @param durationPerFrameMs Optionally override duration per frame + * @param durationPerFrame Optionally override duration per frame */ - public toAnimation(durationPerFrameMs?: number): Animation | null { + public toAnimation(durationPerFrame?: number): Animation | null { const images = this._gif?.images; if (images?.length) { const frames = images.map((image, index) => { @@ -109,7 +109,7 @@ export class Gif implements Loadable { }); this._animation = new Animation({ frames, - frameDuration: durationPerFrameMs + frameDuration: durationPerFrame }); return this._animation; diff --git a/src/engine/Scene.ts b/src/engine/Scene.ts index 77f400284..3f494606b 100644 --- a/src/engine/Scene.ts +++ b/src/engine/Scene.ts @@ -258,8 +258,10 @@ export class Scene implements CanInitialize, CanActiv * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})` * * `onPreUpdate` is called directly before a scene is updated. + * @param engine reference to the engine + * @param elapsed Number of milliseconds elapsed since the last draw. */ - public onPreUpdate(engine: Engine, elapsedMs: number): void { + public onPreUpdate(engine: Engine, elapsed: number): void { // will be overridden } @@ -267,8 +269,10 @@ export class Scene implements CanInitialize, CanActiv * Safe to override onPostUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})` * * `onPostUpdate` is called directly after a scene is updated. + * @param engine reference to the engine + * @param elapsed Number of milliseconds elapsed since the last draw. */ - public onPostUpdate(engine: Engine, elapsedMs: number): void { + public onPostUpdate(engine: Engine, elapsed: number): void { // will be overridden } @@ -278,7 +282,7 @@ export class Scene implements CanInitialize, CanActiv * `onPreDraw` is called directly before a scene is drawn. * */ - public onPreDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void { + public onPreDraw(ctx: ExcaliburGraphicsContext, elapsed: number): void { // will be overridden } @@ -288,7 +292,7 @@ export class Scene implements CanInitialize, CanActiv * `onPostDraw` is called directly after a scene is drawn. * */ - public onPostDraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void { + public onPostDraw(ctx: ExcaliburGraphicsContext, elapsed: number): void { // will be overridden } @@ -381,9 +385,9 @@ export class Scene implements CanInitialize, CanActiv * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event * @internal */ - public _preupdate(engine: Engine, elapsedMs: number): void { - this.emit('preupdate', new PreUpdateEvent(engine, elapsedMs, this)); - this.onPreUpdate(engine, elapsedMs); + public _preupdate(engine: Engine, elapsed: number): void { + this.emit('preupdate', new PreUpdateEvent(engine, elapsed, this)); + this.onPreUpdate(engine, elapsed); } /** @@ -392,9 +396,9 @@ export class Scene implements CanInitialize, CanActiv * Internal _preupdate handler for {@apilink onPostUpdate} lifecycle event * @internal */ - public _postupdate(engine: Engine, elapsedMs: number): void { - this.emit('postupdate', new PostUpdateEvent(engine, elapsedMs, this)); - this.onPostUpdate(engine, elapsedMs); + public _postupdate(engine: Engine, elapsed: number): void { + this.emit('postupdate', new PostUpdateEvent(engine, elapsed, this)); + this.onPostUpdate(engine, elapsed); } /** @@ -403,9 +407,9 @@ export class Scene implements CanInitialize, CanActiv * Internal _predraw handler for {@apilink onPreDraw} lifecycle event * @internal */ - public _predraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void { - this.emit('predraw', new PreDrawEvent(ctx, elapsedMs, this)); - this.onPreDraw(ctx, elapsedMs); + public _predraw(ctx: ExcaliburGraphicsContext, elapsed: number): void { + this.emit('predraw', new PreDrawEvent(ctx, elapsed, this)); + this.onPreDraw(ctx, elapsed); } /** @@ -414,22 +418,22 @@ export class Scene implements CanInitialize, CanActiv * Internal _postdraw handler for {@apilink onPostDraw} lifecycle event * @internal */ - public _postdraw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void { - this.emit('postdraw', new PostDrawEvent(ctx, elapsedMs, this)); - this.onPostDraw(ctx, elapsedMs); + public _postdraw(ctx: ExcaliburGraphicsContext, elapsed: number): void { + this.emit('postdraw', new PostDrawEvent(ctx, elapsed, this)); + this.onPostDraw(ctx, elapsed); } /** * Updates all the actors and timers in the scene. Called by the {@apilink Engine}. * @param engine Reference to the current Engine - * @param elapsedMs The number of milliseconds since the last update + * @param elapsed The number of milliseconds since the last update */ - public update(engine: Engine, elapsedMs: number) { + public update(engine: Engine, elapsed: number) { if (!this.isInitialized) { this._logger.warnOnce(`Scene update called before initialize for scene ${engine.director?.getSceneName(this)}!`); return; } - this._preupdate(engine, elapsedMs); + this._preupdate(engine, elapsed); // TODO differed entity removal for timers let i: number, len: number; @@ -441,19 +445,19 @@ export class Scene implements CanInitialize, CanActiv // Cycle through timers updating timers for (const timer of this._timers) { - timer.update(elapsedMs); + timer.update(elapsed); } - this.world.update(SystemType.Update, elapsedMs); + this.world.update(SystemType.Update, elapsed); // Camera last keeps renders smooth that are based on entity/actor if (this.camera) { - this.camera.update(engine, elapsedMs); + this.camera.update(engine, elapsed); } this._collectActorStats(engine); - this._postupdate(engine, elapsedMs); + this._postupdate(engine, elapsed); this.input.update(); } @@ -461,21 +465,21 @@ export class Scene implements CanInitialize, CanActiv /** * Draws all the actors in the Scene. Called by the {@apilink Engine}. * @param ctx The current rendering context - * @param elapsedMs The number of milliseconds since the last draw + * @param elapsed The number of milliseconds since the last draw */ - public draw(ctx: ExcaliburGraphicsContext, elapsedMs: number) { + public draw(ctx: ExcaliburGraphicsContext, elapsed: number) { if (!this.isInitialized) { this._logger.warnOnce(`Scene draw called before initialize!`); return; } - this._predraw(ctx, elapsedMs); + this._predraw(ctx, elapsed); - this.world.update(SystemType.Draw, elapsedMs); + this.world.update(SystemType.Draw, elapsed); if (this.engine?.isDebug) { this.debugDraw(ctx); } - this._postdraw(ctx, elapsedMs); + this._postdraw(ctx, elapsed); } /** diff --git a/src/engine/TileMap/TileMap.ts b/src/engine/TileMap/TileMap.ts index fbebaaeaf..9618b09e5 100644 --- a/src/engine/TileMap/TileMap.ts +++ b/src/engine/TileMap/TileMap.ts @@ -261,7 +261,7 @@ export class TileMap extends Entity implements HasNestedPointerEvents { ); this.addComponent( new GraphicsComponent({ - onPostDraw: (ctx, elapsedMs) => this.draw(ctx, elapsedMs) + onPostDraw: (ctx, elapsed) => this.draw(ctx, elapsed) }) ); this.addComponent(new DebugGraphicsComponent((ctx, debugFlags) => this.debug(ctx, debugFlags), false)); @@ -559,10 +559,10 @@ export class TileMap extends Entity implements HasNestedPointerEvents { this._pointerEventDispatcher.dispatchEvents(receiver, this.tiles); } - public update(engine: Engine, elapsedMs: number) { + public update(engine: Engine, elapsed: number) { this._initialize(engine); - this.onPreUpdate(engine, elapsedMs); - this.emit('preupdate', new PreUpdateEvent(engine, elapsedMs, this)); + this.onPreUpdate(engine, elapsed); + this.emit('preupdate', new PreUpdateEvent(engine, elapsed, this)); // Update colliders if (!this._oldPos.equals(this.pos) || this._oldRotation !== this.rotation || !this._oldScale.equals(this.scale)) { @@ -583,20 +583,20 @@ export class TileMap extends Entity implements HasNestedPointerEvents { this._oldRotation = this.rotation; this.scale.clone(this._oldScale); this.transform.pos = this.pos; - this.onPostUpdate(engine, elapsedMs); - this.emit('postupdate', new PostUpdateEvent(engine, elapsedMs, this)); + this.onPostUpdate(engine, elapsed); + this.emit('postupdate', new PostUpdateEvent(engine, elapsed, this)); } /** * Draws the tile map to the screen. Called by the {@apilink Scene}. * @param ctx ExcaliburGraphicsContext - * @param elapsedMs The number of milliseconds since the last draw + * @param elapsed The number of milliseconds since the last draw */ - public draw(ctx: ExcaliburGraphicsContext, elapsedMs: number): void { + public draw(ctx: ExcaliburGraphicsContext, elapsed: number): void { if (!this.isInitialized) { return; } - this.emit('predraw', new PreDrawEvent(ctx as any, elapsedMs, this)); // TODO fix event + this.emit('predraw', new PreDrawEvent(ctx as any, elapsed, this)); // TODO fix event let graphics: readonly Graphic[], graphicsIndex: number, graphicsLen: number; @@ -613,14 +613,14 @@ export class TileMap extends Entity implements HasNestedPointerEvents { const offset = offsets[graphicsIndex]; if (graphic) { if (hasGraphicsTick(graphic)) { - graphic?.tick(elapsedMs, this._token); + graphic?.tick(elapsed, this._token); } const offsetY = this.renderFromTopOfGraphic ? 0 : graphic.height - this.tileHeight; graphic.draw(ctx, tile.x * this.tileWidth + offset.x, tile.y * this.tileHeight - offsetY + offset.y); } } } - this.emit('postdraw', new PostDrawEvent(ctx as any, elapsedMs, this)); + this.emit('postdraw', new PostDrawEvent(ctx as any, elapsed, this)); } public debug(gfx: ExcaliburGraphicsContext, debugFlags: DebugConfig) { diff --git a/src/engine/Timer.ts b/src/engine/Timer.ts index e3fbae7cf..fde95e0b2 100644 --- a/src/engine/Timer.ts +++ b/src/engine/Timer.ts @@ -123,12 +123,12 @@ export class Timer { } /** * Updates the timer after a certain number of milliseconds have elapsed. This is used internally by the engine. - * @param elapsedMs Number of elapsed milliseconds since the last update. + * @param elapsed Number of elapsed milliseconds since the last update. */ - public update(elapsedMs: number) { + public update(elapsed: number) { if (this._running) { - this._totalTimeAlive += elapsedMs; - this._elapsedTime += elapsedMs; + this._totalTimeAlive += elapsed; + this._elapsedTime += elapsed; if (this.maxNumberOfRepeats > -1 && this._numberOfTicks >= this.maxNumberOfRepeats) { this._complete = true; diff --git a/src/engine/Util/Clock.ts b/src/engine/Util/Clock.ts index c3bec936e..dd1e2ea7a 100644 --- a/src/engine/Util/Clock.ts +++ b/src/engine/Util/Clock.ts @@ -7,7 +7,7 @@ export interface ClockOptions { /** * Define the function you'd like the clock to tick when it is started */ - tick: (elapsedMs: number) => any; + tick: (elapsed: number) => any; /** * Optionally define the fatal exception handler, used if an error is thrown in tick */ @@ -29,7 +29,7 @@ export interface ClockOptions { * method is unique to your clock implementation. */ export abstract class Clock { - protected tick: (elapsedMs: number) => any; + protected tick: (elapsed: number) => any; private _onFatalException: (e: unknown) => any = () => { /* default nothing */ }; @@ -38,7 +38,7 @@ export abstract class Clock { public fpsSampler: FpsSampler; private _options: ClockOptions; private _elapsed: number = 1; - private _scheduledCbs: [cb: (elapsedMs: number) => any, scheduledTime: number, timing: ScheduledCallbackTiming][] = []; + private _scheduledCbs: [cb: (elapsed: number) => any, scheduledTime: number, timing: ScheduledCallbackTiming][] = []; private _totalElapsed: number = 0; constructor(options: ClockOptions) { this._options = options; @@ -95,7 +95,7 @@ export abstract class Clock { * @param timeoutMs Optionally specify a timeout in milliseconds from now, default is 0ms which means the next possible tick * @param timing Optionally specify a timeout in milliseconds from now, default is 0ms which means the next possible tick */ - public schedule(cb: (elapsedMs: number) => any, timeoutMs: number = 0, timing: ScheduledCallbackTiming = 'preframe') { + public schedule(cb: (elapsed: number) => any, timeoutMs: number = 0, timing: ScheduledCallbackTiming = 'preframe') { // Scheduled based on internal elapsed time const scheduledTime = this._totalElapsed + timeoutMs; this._scheduledCbs.push([cb, scheduledTime, timing]); diff --git a/src/engine/Util/Coroutine.ts b/src/engine/Util/Coroutine.ts index 0707099ef..5cb76aaf3 100644 --- a/src/engine/Util/Coroutine.ts +++ b/src/engine/Util/Coroutine.ts @@ -162,16 +162,16 @@ export function coroutine(...args: any[]): CoroutineInstance { let cancelled = false; const generatorFcn = coroutineGenerator.bind(thisArg) as CoroutineGenerator; const generator = generatorFcn(); - let loop: (elapsedMs: number) => void; + let loop: (elapsed: number) => void; const complete = new Promise((resolve, reject) => { - loop = (elapsedMs: number) => { + loop = (elapsed: number) => { try { if (cancelled) { completed = true; resolve(); return; } - const { done, value } = InsideCoroutineContext.scope(true, () => generator.next(elapsedMs)); + const { done, value } = InsideCoroutineContext.scope(true, () => generator.next(elapsed)); if (done || cancelled) { completed = true; resolve(); diff --git a/src/engine/Util/StateMachine.ts b/src/engine/Util/StateMachine.ts index 4a698a3e4..b15dd7719 100644 --- a/src/engine/Util/StateMachine.ts +++ b/src/engine/Util/StateMachine.ts @@ -4,7 +4,7 @@ export interface State { onEnter?: (context: { from: string; eventData?: any; data: TData }) => boolean | void; onState?: () => any; onExit?: (context: { to: string; data: TData }) => boolean | void; - onUpdate?: (data: TData, elapsedMs: number) => any; + onUpdate?: (data: TData, elapsed: number) => any; } export interface StateMachineDescription { @@ -90,9 +90,9 @@ export class StateMachine { return false; } - update(elapsedMs: number) { + update(elapsed: number) { if (this.currentState.onUpdate) { - this.currentState.onUpdate(this.data, elapsedMs); + this.currentState.onUpdate(this.data, elapsed); } } diff --git a/src/spec/ActionSpec.ts b/src/spec/ActionSpec.ts index 33caabe3f..197cc2fbf 100644 --- a/src/spec/ActionSpec.ts +++ b/src/spec/ActionSpec.ts @@ -331,7 +331,7 @@ describe('Action', () => { }); it('(with options) can be reset', () => { - const moveBy = new ex.MoveByWithOptions(actor, { offset: ex.vec(100, 0), durationMs: 100 }); + const moveBy = new ex.MoveByWithOptions(actor, { offset: ex.vec(100, 0), duration: 100 }); actor.actions.runAction(moveBy); scene.update(engine, 1000); expect(moveBy.isComplete(actor)).toBeTrue(); @@ -356,7 +356,7 @@ describe('Action', () => { expect(actor.pos.x).toBe(0); expect(actor.pos.y).toBe(0); - actor.actions.moveBy({ offset: ex.vec(100, 0), durationMs: 2000 }); + actor.actions.moveBy({ offset: ex.vec(100, 0), duration: 2000 }); scene.update(engine, 1000); expect(actor.pos.x).toBe(50); @@ -405,7 +405,7 @@ describe('Action', () => { expect(actor.pos.x).toBe(0); expect(actor.pos.y).toBe(0); - actor.actions.moveBy({ offset: ex.vec(20, 0), durationMs: 1000 }); + actor.actions.moveBy({ offset: ex.vec(20, 0), duration: 1000 }); scene.update(engine, 500); actor.actions.clearActions(); @@ -421,7 +421,7 @@ describe('Action', () => { describe('moveTo', () => { it('can be reset', () => { - const moveTo = new ex.MoveToWithOptions(actor, { pos: ex.vec(100, 0), durationMs: 500 }); + const moveTo = new ex.MoveToWithOptions(actor, { pos: ex.vec(100, 0), duration: 500 }); actor.actions.runAction(moveTo); scene.update(engine, 1000); expect(moveTo.isComplete(actor)).toBeTrue(); @@ -449,7 +449,7 @@ describe('Action', () => { expect(actor.pos.x).toBe(0); expect(actor.pos.y).toBe(0); - actor.actions.moveTo({ pos: ex.vec(100, 0), durationMs: 1000 }); + actor.actions.moveTo({ pos: ex.vec(100, 0), duration: 1000 }); scene.update(engine, 500); expect(actor.pos.x).toBe(50); @@ -511,7 +511,7 @@ describe('Action', () => { expect(actor.pos.x).toBe(0); expect(actor.pos.y).toBe(0); - actor.actions.moveTo({ pos: ex.vec(20, 0), durationMs: 2000 }); + actor.actions.moveTo({ pos: ex.vec(20, 0), duration: 2000 }); scene.update(engine, 500); actor.actions.clearActions(); @@ -887,7 +887,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle at a speed via ShortestPath (default)', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateTo({ angleRadians: Math.PI / 2, durationMs: 1000 }); + actor.actions.rotateTo({ angle: Math.PI / 2, duration: 1000 }); scene.update(engine, 500); expect(actor.rotation).toBe(Math.PI / 4); @@ -919,7 +919,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle at a speed via LongestPath', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateTo({ angleRadians: Math.PI / 2, durationMs: 3000, rotationType: ex.RotationType.LongestPath }); + actor.actions.rotateTo({ angle: Math.PI / 2, duration: 3000, rotationType: ex.RotationType.LongestPath }); scene.update(engine, 1000); //rotation is currently incremented by rx delta ,so will be negative while moving counterclockwise @@ -952,7 +952,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle at a speed via Clockwise', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateTo({ angleRadians: (3 * Math.PI) / 2, durationMs: 3000, rotationType: ex.RotationType.Clockwise }); + actor.actions.rotateTo({ angle: (3 * Math.PI) / 2, duration: 3000, rotationType: ex.RotationType.Clockwise }); scene.update(engine, 2000); expect(actor.rotation).toBe(Math.PI); @@ -991,7 +991,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle at a speed via CounterClockwise', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateTo({ angleRadians: Math.PI / 2, durationMs: 3000, rotationType: ex.RotationType.CounterClockwise }); + actor.actions.rotateTo({ angle: Math.PI / 2, duration: 3000, rotationType: ex.RotationType.CounterClockwise }); scene.update(engine, 2000); expect(actor.rotation).toBe(ex.canonicalizeAngle(-Math.PI)); @@ -1028,7 +1028,7 @@ describe('Action', () => { it('(with options) can be stopped', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateTo({ angleRadians: Math.PI / 2, durationMs: 1000 }); + actor.actions.rotateTo({ angle: Math.PI / 2, duration: 1000 }); scene.update(engine, 500); expect(actor.rotation).toBe(Math.PI / 4); @@ -1052,7 +1052,7 @@ describe('Action', () => { expect(rotateBy.isComplete()).toBeFalse(); }); it('(with options) can be reset', () => { - const rotateBy = new ex.RotateByWithOptions(actor, { angleRadiansOffset: Math.PI / 2, durationMs: 500 }); + const rotateBy = new ex.RotateByWithOptions(actor, { angleRadiansOffset: Math.PI / 2, duration: 500 }); actor.actions.runAction(rotateBy); scene.update(engine, 1000); expect(rotateBy.isComplete()).toBeTrue(); @@ -1079,7 +1079,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle by a certain time via ShortestPath (default)', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, durationMs: 2000 }); + actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, duration: 2000 }); scene.update(engine, 1000); expect(actor.rotation).toBe(Math.PI / 4); @@ -1109,7 +1109,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle by a certain time via LongestPath', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, durationMs: 3000, rotationType: ex.RotationType.LongestPath }); + actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, duration: 3000, rotationType: ex.RotationType.LongestPath }); scene.update(engine, 1000); expect(actor.rotation).toBe(ex.canonicalizeAngle((-1 * Math.PI) / 2)); @@ -1141,7 +1141,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle by a certain time via Clockwise', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, durationMs: 1000, rotationType: ex.RotationType.Clockwise }); + actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, duration: 1000, rotationType: ex.RotationType.Clockwise }); scene.update(engine, 500); expect(actor.rotation).toBe(Math.PI / 4); @@ -1173,7 +1173,7 @@ describe('Action', () => { it('(with options) can be rotated to an angle by a certain time via CounterClockwise', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, durationMs: 3000, rotationType: ex.RotationType.LongestPath }); + actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, duration: 3000, rotationType: ex.RotationType.LongestPath }); scene.update(engine, 1000); expect(actor.rotation).toBe(ex.canonicalizeAngle((-1 * Math.PI) / 2)); @@ -1202,7 +1202,7 @@ describe('Action', () => { it('(with options) can be stopped', () => { expect(actor.rotation).toBe(0); - actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, durationMs: 2000 }); + actor.actions.rotateBy({ angleRadiansOffset: Math.PI / 2, duration: 2000 }); scene.update(engine, 1000); actor.actions.clearActions(); @@ -1225,7 +1225,7 @@ describe('Action', () => { expect(scaleTo.isComplete()).toBeFalse(); }); it('(with options) can be reset', () => { - const scaleTo = new ex.ScaleToWithOptions(actor, { scale: ex.vec(2, 2), durationMs: 500 }); + const scaleTo = new ex.ScaleToWithOptions(actor, { scale: ex.vec(2, 2), duration: 500 }); actor.actions.runAction(scaleTo); scene.update(engine, 1000); expect(scaleTo.isComplete()).toBeTrue(); @@ -1257,7 +1257,7 @@ describe('Action', () => { expect(actor.scale.x).toBe(1); expect(actor.scale.y).toBe(1); - actor.actions.scaleTo({ scale: ex.vec(2, 4), durationMs: 2000 }); + actor.actions.scaleTo({ scale: ex.vec(2, 4), duration: 2000 }); scene.update(engine, 1000); expect(actor.scale.x).toBe(1.5); @@ -1352,7 +1352,7 @@ describe('Action', () => { expect(scaleBy.isComplete()).toBeFalse(); }); it('(with options) can be reset', () => { - const scaleBy = new ex.ScaleByWithOptions(actor, { scaleOffset: ex.vec(1, 1), durationMs: 500 }); + const scaleBy = new ex.ScaleByWithOptions(actor, { scaleOffset: ex.vec(1, 1), duration: 500 }); actor.actions.runAction(scaleBy); scene.update(engine, 1000); expect(scaleBy.isComplete()).toBeTrue(); @@ -1381,7 +1381,7 @@ describe('Action', () => { expect(actor.scale.x).toBe(1); expect(actor.scale.y).toBe(1); - actor.actions.scaleBy({ scaleOffset: ex.vec(4, 4), durationMs: 1000 }); + actor.actions.scaleBy({ scaleOffset: ex.vec(4, 4), duration: 1000 }); scene.update(engine, 500); expect(actor.scale.x).toBe(3); @@ -1446,7 +1446,7 @@ describe('Action', () => { expect(actor.scale.x).toBe(1); expect(actor.scale.y).toBe(1); - actor.actions.scaleBy({ scaleOffset: ex.vec(4, 4), durationMs: 1250 }); + actor.actions.scaleBy({ scaleOffset: ex.vec(4, 4), duration: 1250 }); scene.update(engine, 500); diff --git a/src/spec/CurveActionSpec.ts b/src/spec/CurveActionSpec.ts index 3e1c15195..c7184150f 100644 --- a/src/spec/CurveActionSpec.ts +++ b/src/spec/CurveActionSpec.ts @@ -35,7 +35,7 @@ describe('A actor can curve', () => { actor.actions.curveTo({ controlPoints: [ex.vec(100, 100), ex.vec(0, 0), ex.vec(100, 200)], - durationMs: 1000 + duration: 1000 }); clock.step(0); @@ -53,7 +53,7 @@ describe('A actor can curve', () => { actor.actions.curveBy({ controlPoints: [ex.vec(0, 100), ex.vec(0, 100), ex.vec(100, 200)], - durationMs: 1000 + duration: 1000 }); clock.step(0); @@ -71,7 +71,7 @@ describe('A actor can curve', () => { actor.actions.curveBy({ controlPoints: [ex.vec(0, 100), ex.vec(0, 100), ex.vec(100, 200)], - durationMs: 1000 + duration: 1000 }); clock.step(0); @@ -90,7 +90,7 @@ describe('A actor can curve', () => { actor.actions.curveTo({ controlPoints: [ex.vec(0, 100), ex.vec(0, 100), ex.vec(100, 200)], - durationMs: 1000 + duration: 1000 }); clock.step(0);