加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
我想播放一组图片,一共5张,然后我用了下面的代码:
const _Create_Background = Scene_Title.prototype.createBackground; Scene_Title.prototype.createBackground = function() { _Create_Background.apply(this, arguments); const titleCommandButtonCursorSpriteTextureArray = []; for (const image of titleCommandButtonCursorSpriteJsonObject) { console.log("image: ", "img/" + image + ".png") let texture = PIXI.Texture.from("img/" + image + ".png"); titleCommandButtonCursorSpriteTextureArray.push(texture); } // let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray, true); let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray); animatedSprite.animationSpeed = 1; animatedSprite.loop = true; animatedSprite.x = titleCommandButtonCursorSpriteRect.x; animatedSprite.y = titleCommandButtonCursorSpriteRect.y; animatedSprite.width = titleCommandButtonCursorSpriteRect.width; animatedSprite.height = titleCommandButtonCursorSpriteRect.height; animatedSprite.onComplete = () => { }; animatedSprite.gotoAndPlay(0); console.log("animatedSprite: ", animatedSprite) this.addChild(animatedSprite); };
const _Create_Background = Scene_Title.prototype.createBackground;
Scene_Title.prototype.createBackground = function() {
_Create_Background.apply(this, arguments);
const titleCommandButtonCursorSpriteTextureArray = [];
for (const image of titleCommandButtonCursorSpriteJsonObject) {
console.log("image: ", "img/" + image + ".png")
let texture = PIXI.Texture.from("img/" + image + ".png");
titleCommandButtonCursorSpriteTextureArray.push(texture);
}
// let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray, true);
let animatedSprite = new PIXI.AnimatedSprite(titleCommandButtonCursorSpriteTextureArray);
animatedSprite.animationSpeed = 1;
animatedSprite.loop = true;
animatedSprite.x = titleCommandButtonCursorSpriteRect.x;
animatedSprite.y = titleCommandButtonCursorSpriteRect.y;
animatedSprite.width = titleCommandButtonCursorSpriteRect.width;
animatedSprite.height = titleCommandButtonCursorSpriteRect.height;
animatedSprite.onComplete = () => {
};
animatedSprite.gotoAndPlay(0);
console.log("animatedSprite: ", animatedSprite)
this.addChild(animatedSprite);
};
titleCommandButtonCursorSpriteJsonObject是个图片路径字符串数组,titleCommandButtonCursorSpriteRect也是从插件参数传回来的,但是只要使用gotoAndPlay或者Play,animatedSprite._texture会变成undefined,就会出现"TypeError: Cannot read property '_uvs' of undefined"
不用gotoAndPlay或者Play,会固定正常显示第一张图,我还发现,这时候animatedSprite._texture是第一张图,以下是错误日志:
|