UNPKG

pixi-fusion

Version:

This module offers a set of common components needed for playing games.

22 lines (21 loc) 682 B
import { useMemo } from "react"; import { Sprite } from "pixi.js"; import { useTextures } from "./useTexture"; import { useObject } from "./useObject"; export const useSprite = ({ texture = "", ...options }) => { const textureKeys = useMemo(() => { return [...(texture ? [texture] : [])]; }, [texture]); const { isFetched } = useTextures({ keys: textureKeys }); const sprite = useMemo(() => { if (!isFetched) { return null; } if (texture) { return Sprite.from(texture); } return new Sprite({}); }, [texture, isFetched]); useObject({ object: sprite, ...options }); return sprite; };