Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

资源异步加载问题 cc.loader.loadRes

$
0
0

@745872343 写道:

循环创建预制体的实例(按钮),之后用获取动态资源设置按钮的图标,但只有最后一个按钮设置图片成功。感觉是异步加载资源时,再次调用会中断前一次,所以只有最后一次成功。不知如何解决,求大神指点~

代码如下:

//创建按钮
createFaceItem: function () {

    for (var i = 0; i < 18; i++) {
        if (i % 6 == 0) {
            this.facePageView.addPage(this.createPage());
        }
        var pages = this.facePageView.getPages();

        var page = pages[parseInt(i / 6)];

        var newFaceItem = cc.instantiate(this.faceItem);

        var clickEventHandler = new cc.Component.EventHandler();
        clickEventHandler.target = this.node; //这个 node 节点是事件处理代码组件所属的节点
        clickEventHandler.component = "pluginItemControl"
        clickEventHandler.handler = "onBtnClicked";
        // clickEventHandler.customEventData = "foobar";    //传递参数

        var button = newFaceItem.getComponent(cc.Button);
        button.clickEvents.push(clickEventHandler);

        //设置按钮图标
        cc.loader.loadRes(resList.pluginMicrophoneIcon, cc.SpriteFrame, function (err, spriteFrame) {
            newFaceItem.getChildByName('face').getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        newFaceItem.tag = i;
        newFaceItem.setPosition(cc.p(0, 0));
        newFaceItem.width = sceneFit.faceItemSize.width;
        newFaceItem.height = sceneFit.faceItemSize.height;

        page.addChild(newFaceItem);
    }
},

帖子: 3

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>