silphius/app/react-components/sprite.jsx

28 lines
653 B
React
Raw Normal View History

2024-06-12 14:31:12 -05:00
import {Sprite as PixiSprite} from '@pixi/react';
2024-06-14 12:05:02 -05:00
2024-06-27 13:56:43 -05:00
import {useAsset} from '@/context/assets.js';
2024-06-12 14:31:12 -05:00
2024-07-01 18:12:53 -05:00
export default function Sprite({entity, ...rest}) {
2024-06-14 12:05:02 -05:00
const asset = useAsset(entity.Sprite.source);
2024-06-12 14:31:12 -05:00
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
2024-06-22 12:12:13 -05:00
anchor={entity.Sprite.anchor}
2024-07-02 10:27:25 -05:00
scale={entity.Sprite.scale}
2024-06-12 14:31:12 -05:00
texture={texture}
2024-06-12 19:39:40 -05:00
x={Math.round(entity.Position.x)}
y={Math.round(entity.Position.y)}
2024-07-01 18:12:53 -05:00
{...rest}
2024-06-12 14:31:12 -05:00
/>
);
}