silphius/app/react-components/sprite.jsx
2024-06-27 13:57:02 -05:00

26 lines
594 B
JavaScript

import {Sprite as PixiSprite} from '@pixi/react';
import {useAsset} from '@/context/assets.js';
export default function Sprite({entity}) {
const asset = useAsset(entity.Sprite.source);
if (!asset) {
return false;
}
let texture;
if (asset.textures) {
const animation = asset.animations[entity.Sprite.animation]
texture = animation[entity.Sprite.frame];
}
else {
texture = asset;
}
return (
<PixiSprite
anchor={entity.Sprite.anchor}
texture={texture}
x={Math.round(entity.Position.x)}
y={Math.round(entity.Position.y)}
/>
);
}