问答

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

作者:admin 2021-07-10 我要评论

let type = 'WebGL', Application = PIXI.Application, loader = PIXI.loader, resources = PIXI.loader.resources, Sprite = PIXI.Sprite, Container = PIXI.Co...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
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;
###

这个报错说没有 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的原因。

###

那位大佬能帮忙解决一下,小弟感激不尽

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • elementUI表单Object.assign处理后无法

    elementUI表单Object.assign处理后无法

  • nacos作为配置中,有时可以加载到配置

    nacos作为配置中,有时可以加载到配置

  • font-spider压缩字体后,文件大小没有

    font-spider压缩字体后,文件大小没有

  • Vue SSR babel node_modules中的一个包

    Vue SSR babel node_modules中的一个包

腾讯云代理商
海外云服务器