LoginSignup
0
0

pixi.jsのcontainerからテクスチャーを作る

Last updated at Posted at 2021-08-02

pixi.jsのcontainerからtextureをつくるやり方です。
こんな感じのクラスを作ってみました。

class ContainerToTexture {
  private width: number;
  private height: number;
  private texture: PIXI.RenderTexture;
  constructor(width: number, height: number){
    this.resize(width, height);
  }
  /**
   * コンテナをテクスチャーに変換する
   * @param container 変換するcontainer
   * @returns 生成したテクスチャー
   */
  public convert(container: PIXI.Container){
    core.app.renderer.render(container, this.texture);//rendererをお使いにの場所に変えてください
    return this.texture;
  }
  //テクスチャーのサイズを変更
  public resize(width: number, height: number){
    this.width = width;
    this.height = height;
    this.texture = new PIXI.RenderTexture(
      new PIXI.BaseRenderTexture({width: width, height: height})
    );
  }
}

幅と高さを指定してクラスを作ってconvert()で変換したいcontainerを渡してやるとテクスチャーになって返ってきます。

おまけ

★pixi.jsの基本的な使い方の記事
【PixiJS入門】基本的な使い方まとめ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0