Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

照着教程抄的结果报了一个Cannot read property 'textures' of undefined?

let type = 'WebGL',
    Application = PIXI.Application,
    loader = PIXI.loader,
    resources = PIXI.loader.resources,
    Sprite = PIXI.Sprite,
    Container = PIXI.Container,
    Graphics = PIXI.Graphics,
    TextureCache = PIXI.utils.TextureCache;

if (!PIXI.utils.isWebGLSupported()) {
    type = 'canvas';
}

PIXI.utils.sayHello(type);

let app = new Application({
    width: window.innerWidth,
    height: window.innerHeight,
    antialias: true, //使得字体的边界和几何图形更加圆滑 default: false
    transparent: true, //透明度设置 default: false
    resolution: 1, // default: 1
});
//游戏场景
gameScene = new Container();
//添加到底层进行显示
app.stage.addChild(gameScene);
//结束场景
gameOverScene = new Container();
app.stage.addChild(gameOverScene);
//游戏结束场景默认不显示
gameOverScene.visible = false;
//引入图片json文件
let id = resources['images/game.json'].textures;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这个报错说没有 textures,而你的代码中涉及这个的只有

let id = resources['images/game.json'].textures;

由此有2种可能
1.本身就没有textures这个属性(没有完整代码不好评说),比如我觉得这里应该是(注意是texture而不是textures):

let id = resources['images/game.json'].texture;
  1. 语法有问题,对此最安全的语法是:
let id = (resources['images/game.json'])["textures"];

不过就我了解,更可能是1的原因。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...