silphius/app/ecs-components/sprite.js

30 lines
867 B
JavaScript
Raw Normal View History

2024-06-26 21:08:09 -05:00
import Component from '@/ecs/component.js';
export default class Sprite extends Component {
2024-07-03 21:56:55 -05:00
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};
}
};
}
2024-07-02 12:00:12 -05:00
async load(instance) {
instance.$$sourceJson = await this.ecs.readJson(instance.source);
}
2024-06-26 21:08:09 -05:00
static properties = {
2024-07-03 21:56:55 -05:00
anchorX: {defaultValue: 0.5, type: 'float32'},
anchorY: {defaultValue: 0.5, type: 'float32'},
2024-06-26 21:08:09 -05:00
animation: {type: 'string'},
elapsed: {type: 'float32'},
frame: {type: 'uint16'},
frames: {type: 'uint16'},
2024-07-03 21:56:55 -05:00
scaleX: {defaultValue: 1, type: 'float32'},
scaleY: {defaultValue: 1, type: 'float32'},
2024-06-26 21:08:09 -05:00
source: {type: 'string'},
speed: {type: 'float32'},
};
}