Project1

标题: 不知道为什么PIXI.AnimatedSprite Play()的时候一直报错 [打印本页]

作者: Arrose    时间: 2024-2-2 22:45
标题: 不知道为什么PIXI.AnimatedSprite Play()的时候一直报错
我想播放一组图片,一共5张,然后我用了下面的代码:
JAVASCRIPT 代码复制
  1. const _Create_Background = Scene_Title.prototype.createBackground;
  2.     Scene_Title.prototype.createBackground = function() {
  3.         _Create_Background.apply(this, arguments);
  4.         const titleCommandButtonCursorSpriteTextureArray = [];
  5.         for (const image of titleCommandButtonCursorSpriteJsonObject) {
  6.             console.log("image: ", "img/" + image + ".png")
  7.             let texture = PIXI.Texture.from("img/" + image + ".png");
  8.             titleCommandButtonCursorSpriteTextureArray.push(texture);
  9.         }
  10.  
  11.         // let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray, true);
  12.         let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray);
  13.         animatedSprite.animationSpeed = 1;
  14.         animatedSprite.loop = true;
  15.         animatedSprite.x = titleCommandButtonCursorSpriteRect.x;
  16.         animatedSprite.y = titleCommandButtonCursorSpriteRect.y;
  17.         animatedSprite.width = titleCommandButtonCursorSpriteRect.width;
  18.         animatedSprite.height = titleCommandButtonCursorSpriteRect.height;
  19.         animatedSprite.onComplete = () => {
  20.  
  21.         };
  22.         animatedSprite.gotoAndPlay(0);
  23.         console.log("animatedSprite: ", animatedSprite)
  24.         this.addChild(animatedSprite);
  25.  
  26.     };


titleCommandButtonCursorSpriteJsonObject是个图片路径字符串数组,titleCommandButtonCursorSpriteRect也是从插件参数传回来的,但是只要使用gotoAndPlay或者Play,animatedSprite._texture会变成undefined,就会出现"TypeError: Cannot read property '_uvs' of undefined"

不用gotoAndPlay或者Play,会固定正常显示第一张图,我还发现,这时候animatedSprite._texture是第一张图,以下是错误日志:

SharedScreenshot.jpg (160.26 KB, 下载次数: 15)

SharedScreenshot.jpg

SharedScreenshot2.jpg (86.25 KB, 下载次数: 13)

SharedScreenshot2.jpg

作者: Arrose    时间: 2024-2-2 22:46
有大佬知道这是为啥吗




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1