27 lines
619 B
JavaScript
27 lines
619 B
JavaScript
import {Sprite as PixiSprite} from '@pixi/react';
|
|
|
|
import {useAsset} from '@/context/assets.js';
|
|
|
|
export default function Sprite({entity, ...rest}) {
|
|
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)}
|
|
{...rest}
|
|
/>
|
|
);
|
|
} |