// Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; import SoundManager from "./SoundsManager"; import GameData from "./GameData"; @ccclass export default class NewClass extends cc.Component { @property(cc.Label) soundLabel: cc.Label = null; @property(cc.Label) musicLabel: cc.Label = null; controlSound() { SoundManager.instance.playEffect('click'); if(GameData.instance.soundEnabled) { this.soundLabel.string = 'OFF'; } else { this.soundLabel.string = 'ON'; } GameData.instance.setSoundEnabled(!GameData.instance.soundEnabled); } controlMusic() { SoundManager.instance.playEffect('click'); if(GameData.instance.musicEnabled) { this.musicLabel.string = 'OFF'; GameData.instance.setMusicEnabled(!GameData.instance.musicEnabled); SoundManager.instance.stopMusic(); } else { this.musicLabel.string = 'ON'; GameData.instance.setMusicEnabled(!GameData.instance.musicEnabled); SoundManager.instance.playMusic('Judgement', true); } } onLoad() { if(GameData.instance.soundEnabled) { this.soundLabel.string = 'ON'; } else { this.soundLabel.string = 'OFF'; } if(GameData.instance.musicEnabled) { this.musicLabel.string = 'ON'; } else { this.musicLabel.string = 'OFF'; } } }