美文网首页杂谈
cocos creator动态更换sprite

cocos creator动态更换sprite

作者: LXEP | 来源:发表于2019-08-01 15:36 被阅读0次
properties: {
    audioBtn: {
        default: null,
        type: cc.Node
    },
    audioSource: {
        default: null,
        type: cc.AudioSource
    },
},

start () {
    this.audioBtn.on('touchstart', this.playAudio, this);
    this.changeIcon('icon_default');
},

changeIcon (image) {
    const sprite = this.audioBtn.getComponent(cc.Sprite);

    cc.loader.loadRes(image, cc.SpriteFrame, (err, spriteFrame) => {
        if (sprite.node != null) {
            sprite.spriteFrame = spriteFrame;
        }
    });
},

相关文章

网友评论

    本文标题:cocos creator动态更换sprite

    本文链接:https://www.haomeiwen.com/subject/sizqdctx.html