cocos creator动态更换sprite

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)