- Creator 版本: 2.4.5
用cc.resources.load加载图片写在onload里面一切正常,然后封装到方法里边之后出现问题了,请大佬们帮忙看看。
creatNode(name) { let node = new cc.Node(name); node.parent = this.node; return node; }, loadPic(index) { let fileName = "'zhengtu_" + index + "'"; cc.log(fileName); cc.resources.load(fileName, cc.Texture2D, (err, texture) => { this.picTexture = texture; cc.log(this.picTexture); }); }, onLoad() { this.picOrder = 0; this.loadPic(this.picOrder); let thumbnail = this.creatNode('thumbnail'); let thumbnailSprite = thumbnail.addComponent(cc.Sprite); cc.log(this.picTexture); thumbnailSprite.spriteFrame = new cc.SpriteFrame(this.picTexture); thumbnail.scale = 0.5; thumbnail.opacity = 100; },
问题一,上边的picLoad方法里边fileName打印出来的结果是’zhengtu_0’,加载不了图片,然后我直接把这个复制进cc.resources.load方法里就可以正常加载到图片,不太明白这是为什么
问题二,在picLoad方法里把texture赋值给this.picTexture后,方法里打印的this.picTexture是对的,但是在方法外的this.picTexture的打印结果是undefined,我尝试在onload里边picLoad方法之前定义一个this.picTexture=new cc.texture2D,结果方法外的this.picTexture也还是一样没有加载到图片
还请大佬帮忙看看是什么问题,谢谢了

多了路径就不对了