summaryrefslogtreecommitdiff
path: root/src/engine/components/Sprite.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-01 19:45:33 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-01 19:45:33 -0700
commitd08e0105cbc59c6cc804f04aaf1e4e625a13960c (patch)
tree57d5270e146ce2e0c5cfba30e172ab87a2210514 /src/engine/components/Sprite.ts
parenta8d07a790395e14fe7aedd3ba638db466f9c0842 (diff)
downloadthe-abstraction-engine-d08e0105cbc59c6cc804f04aaf1e4e625a13960c.tar.gz
the-abstraction-engine-d08e0105cbc59c6cc804f04aaf1e4e625a13960c.zip
eyes follow cursor
Diffstat (limited to 'src/engine/components/Sprite.ts')
-rw-r--r--src/engine/components/Sprite.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/engine/components/Sprite.ts b/src/engine/components/Sprite.ts
index 6a66a5c..82d7011 100644
--- a/src/engine/components/Sprite.ts
+++ b/src/engine/components/Sprite.ts
@@ -1,5 +1,6 @@
import { Component, ComponentNames } from ".";
import type { Dimension2D, DrawArgs, Coord2D } from "../interfaces";
+import { clamp } from "../utils";
export class Sprite extends Component {
private sheet: HTMLImageElement;
@@ -31,6 +32,11 @@ export class Sprite extends Component {
this.currentFrame = 0;
}
+ public fillTimingsFromSprite(sprite: Sprite) {
+ this.msSinceLastFrame = clamp(sprite.msSinceLastFrame, 0, this.msPerFrame);
+ this.currentFrame = clamp(sprite.currentFrame, 0, this.numFrames - 1);
+ }
+
public update(dt: number) {
this.msSinceLastFrame += dt;
if (this.msSinceLastFrame >= this.msPerFrame) {