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;
|
2024-07-02 12:00:12 -05:00
|
|
|
if (asset.data.animations) {
|
|
|
|
texture = asset.animations[entity.Sprite.animation][entity.Sprite.frame];
|
2024-06-12 14:31:12 -05:00
|
|
|
}
|
|
|
|
else {
|
2024-07-02 12:00:12 -05:00
|
|
|
texture = asset.textures[''];
|
2024-06-12 14:31:12 -05:00
|
|
|
}
|
|
|
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|