杂谈

cocos creator动态更换sprite

2019-08-01  本文已影响0人  LXEP
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;
        }
    });
},
上一篇下一篇

猜你喜欢

热点阅读