pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.33k stars 177 forks source link

react-pixi export new pixi() ? #347

Closed yzbaoo closed 2 years ago

yzbaoo commented 2 years ago

Description

i want to manage textureCache, but,when i use<Sprite image="***">, how do i get the textureCache or BaseTextureCache?

Additional info

yzbaoo commented 2 years ago
import { Stage, Sprite } from '@inlet/react-pixi';
import * as PIXI from 'pixi.js';

export default () => {
  console.log(PIXI.utils.TextureCache); //  Sprite props is image, i can't log TextureCache. texture is ok
  return (
    <div className="pixi-page">
      <Stage width={window.innerWidth} height={window.innerHeight}>
        <Sprite
          width={window.innerWidth}
          height={window.innerHeight}
          image="https://asset.txqn.huohua.cn/image/e82a8354-00cb-423c-aa89-ca6ac9212d6f.png"
          texture={PIXI.Texture.from(
                      'https://asset.txqn.huohua.cn/image/e82a8354-00cb-423c-aa89-ca6ac9212d6f.png'
                    )}
        />
      </Stage>
    </div>
  );
};
inlet commented 2 years ago

Hi @yzbaoo,

Please use Github issues for code bugs/feature requests only, these kind of questions can be asked in our Slack channel where the react-pixi community can help you.

To answer your question. If you'd like to control the texture it's best to not set the image prop as this will create a texture for you. Instead use the texture prop with your texture.

Example:

// create your texture somewhere
const texture = PIXI.Texture.from(
  "https://asset.txqn.huohua.cn/image/e82a8354-00cb-423c-aa89-ca6ac9212d6f.png"
);

// and use it later in any sprite
<Sprite texture={texture}>