如何更改Pixi的AnimatedSprite的纹理

时间:2018-07-05 09:01:13

标签: javascript pixi.js

我想更改将要播放的精灵集。 我在状态中创建两个纹理。 在两秒钟内,我将一个动画切换到另一个动画。 如何替换动画纹理?

responseResultType

我这样做:

states: any = {
  idle: [],
  run : [],
};

loadPlayer() {
  this.loadIdle();
  this.loadRun();
  this.activeState      = this.states.idle;
  const player          = new PIXI.extras.AnimatedSprite(this.activeState);
  player.animationSpeed = 0.1;
  player.gotoAndPlay(0);
  player.name = 'player';
  this.container.addChild(player);
  setTimeout(() => {
    this.changeState(this.states.run);
  }, 2000)
}
changeState(state: any) {
  this.activeState = state;
  const player: AnimatedSprite | DisplayObject = this.container.getChildByName('player');
}

loadIdle() {
  const texture = PIXI.Texture.fromFrame('player0.png');
  this.states.idle.push(texture);
}

loadRun() {
  for (let i = 0; i < 6; i++) {
    const texture = PIXI.Texture.fromFrame('player' + i + '.png');
    this.states.run.push(texture);
  }
}

0 个答案:

没有答案