silphius/app/react-components/sprite.jsx
2024-06-22 12:12:13 -05:00

26 lines
593 B
JavaScript

import {Sprite as PixiSprite} from '@pixi/react';
import useAsset from '@/hooks/use-asset.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)}
/>
);
}