Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Canvas 如何创建PIXI.texture的新实例_Canvas_Pixi.js - Fatal编程技术网

Canvas 如何创建PIXI.texture的新实例

Canvas 如何创建PIXI.texture的新实例,canvas,pixi.js,Canvas,Pixi.js,我正在使用PIXI从精灵表图像创建精灵,并尝试通过更改纹理帧的位置来设置它们的动画: // creating new instance of PXI.texure var texture = new PIXI.Texture.fromImage('my-start-frame-name'); // creating sprite var runner = new PIXI.Sprite(texture); // this is the frame I'm using to

我正在使用PIXI从精灵表图像创建精灵,并尝试通过更改纹理帧的位置来设置它们的动画:

  // creating new instance of PXI.texure
  var texture = new PIXI.Texture.fromImage('my-start-frame-name');
  // creating sprite
  var runner = new PIXI.Sprite(texture);


  // this is the frame I'm using to change the picture in sprite sheet
  var frame = new PIXI.Rectangle(0, 0, 100, 100);

  // animating the sprite
  var interval = setInterval(function () {
    // moving frame one unit to right
    frame.position.x += 100;
    runner.texture.frame = frame;

    //  ending animation
    if (frame.position.x == 1000) {
       frame.position.x = 0;
       clearInterval(interval);
    }
  }, 50);
问题是,当我从单个精灵图纸创建多个精灵时,所有纹理都是相等的:

texture1 == texture2; // true
从而使所有的精灵都在一起


注意:如果我对不同的精灵使用不同的精灵图纸图像,所有精灵都会分别设置动画,这是我所期望的。

您的问题可能在这里runner.texture.frame=frame。由于runner已经是一个纹理实例,您希望更改该实例的帧,而不是原始纹理(即纹理)的帧

更改为该选项将解决以下问题:runner.frame=frame


类似的线程

我之前已经向您提到过这一点,但是您尝试手动创建动画而不是使用PIXI MovieClip有什么原因吗??它正是为了这个目的而建造的。您传入一个帧列表,它会自动为您渲染动画。省省你自己的麻烦吧。@Karmacon不,没有理由不使用movieClip。似乎我错过了你的评论,现在我看到了。我现在要读它的文档,把我的动画改成movieClip。非常感谢你!这个例子应该有你需要的一切