15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pixi.jsわすれたときようまとめ

Last updated at Posted at 2017-08-01

Pixi.jsをやっているときに調べたことなど。
環境
v4.5.0

hello pixi.js

とりあえずここからはじめた。

ベースクラス

ベースクラスをつくった。
諸事情によりTypeScript
よく使う関数とかはここにまとめておいて使うとべんりかなと思ったので。

PixiBase.ts
import * as PIXI from 'pixi.js';

export class PixiBase{
  protected app: PIXI.Application;
  protected loader: PIXI.loaders.Loader;
  protected window: {w:number, h: number};


  constructor(w: number, h: number, opt:PIXI.IApplicationOptions, parentId:string){
    this.app = new PIXI.Application(w, h, opt);

    const elem:HTMLElement = document.getElementById(parentId);
    elem.appendChild(this.app.view);
    console.log("base");

    this.window = {w: w, h: h};

    this.loader = new PIXI.loaders.Loader();

    this.app.ticker.add(()=> {

        this.animate();
    });
  }

  protected setSpirte(sprite:PIXI.Sprite, x:number, y:number): void{
    sprite.anchor.set(0.5);
    sprite.x = x;
    sprite.y = y;
    this.app.stage.addChild(sprite);
  }

  protected animate():void{

  }


}

shaderのuniformわたすやつ

基本これ
http://pixijs.github.io/examples/#/basics/custom-filter.js

onLoadedShaderのなかをこう。

test.ts
let uniforms = {
  "time": {type: "f1", value: 0.0},
  "resolution" : {type: "v2"}
}

this.filter = new PIXI.Filter(null, res.strip.data, uniforms);

this.text.filters = [this.filter];

新しく渡す時

this.text.filters[0].uniforms.time = this.time

こんなかんじで。

指定できるタイプ
https://github.com/pixijs/pixi.js/issues/2570
で書いてあった、
https://github.com/pixijs/pixi.js/blob/364c2457c6693d6e3ab68786539c53d566503e7b/src/core/renderers/webgl/shaders/Shader.js#L232-L463
見ればいけそうだけど、これいつのcommitなんだろう。。

texcoord問題

別記事にまとめた
http://qiita.com/sa-k0/items/015937db7c9dfb43465f

画像に保存したい時

pixiというよりはcanvasだけど

$('#result-canvas').on('click', ()=>{
  var canvas:HTMLCanvasElement = <HTMLCanvasElement>document.getElementById('canvas');

  var img = new Image();
  var type = 'image/png';
  img.src = canvas.toDataURL(type);
  img.onload = function(){
    window.location.href = img.src;
  };
});

PIXI独自の注意点としてoptionの
preserveDrawingBufferはtrueに設定しておく。
http://www.html5gamedevs.com/topic/17141-saving-pixi-to-image-using-todataurl-get-black-rectangle/

15
16
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
15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?