TypeError: atlas.getSpriteFrame is not a function
生活随笔
收集整理的這篇文章主要介紹了
TypeError: atlas.getSpriteFrame is not a function
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.資源結構如下:
?
2.在使用cc.loader.loadRes動態異步加載cc.SpriteAtlas資源時出現這個錯誤,代碼如下:
var self = this;var url = "resources/test_atlas/atlas";var res = cc.loader.getRes(url, cc.SpriteAtlas);cc.loader.release(res);cc.loader.loadRes(url, cc.SpriteAtlas, function (err, atlas) {cc.loader.setAutoRelease(url, true);var node = new cc.Node();self.node.addChild(node);node.position = cc.v2(0, 0);var sprite = node.addComponent(cc.Sprite);sprite.spriteFrame = atlas.getSpriteFrame('sheep_run_0');});?
2.原因是url路徑不對,不應該包含resources。路徑不對竟然報函數錯誤!
var url = "test_atlas/atlas";(PS:動態加載資源都必須放置在?resources?文件夾或它的子文件夾下。resources?需要在 assets 文件夾中手工創建,并且必須位于 assets 的根目錄下。)
?
以上。
轉載于:https://www.cnblogs.com/chevin/p/8002141.html
總結
以上是生活随笔為你收集整理的TypeError: atlas.getSpriteFrame is not a function的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简单工厂模式的创建
- 下一篇: 在Ubuntu 16.04下安装Matl