silphius/app/ecs-components/sprite.js
2024-07-03 21:56:55 -05:00

30 lines
867 B
JavaScript

import Component from '@/ecs/component.js';
export default class Sprite extends Component {
instanceFromSchema() {
return class SpriteInstance extends super.instanceFromSchema() {
get anchor() {
return {x: this.anchorX, y: this.anchorY};
}
get scale() {
return {x: this.scaleX, y: this.scaleY};
}
};
}
async load(instance) {
instance.$$sourceJson = await this.ecs.readJson(instance.source);
}
static properties = {
anchorX: {defaultValue: 0.5, type: 'float32'},
anchorY: {defaultValue: 0.5, type: 'float32'},
animation: {type: 'string'},
elapsed: {type: 'float32'},
frame: {type: 'uint16'},
frames: {type: 'uint16'},
scaleX: {defaultValue: 1, type: 'float32'},
scaleY: {defaultValue: 1, type: 'float32'},
source: {type: 'string'},
speed: {type: 'float32'},
};
}