Main_Sound.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. button: cc.Button,
  5. },
  6. // 存储数据:cc.sys.localStorage.setItem(“key”,”value”)
  7. // 获取数据:cc.sys.localStorage.getItem(“key”)
  8. // 移除数据:cc.sys.localStorage.removeItem(“key”)
  9. // 清除所有:cc.sys.localStorage.clear()
  10. // use this for initialization
  11. onLoad: function () {
  12. this.button.node.on('click', this.callback, this);
  13. console.log('yinyue',Global.NoSound );
  14. var self = this;
  15. if(Global.NoSound == false){
  16. cc.loader.loadRes('texture/声音开', cc.SpriteFrame, function (err, spriteFrame) {
  17. self.node.getChildByName('Label').getComponent(cc.Sprite).spriteFrame = spriteFrame;
  18. });
  19. }else{
  20. cc.loader.loadRes('texture/声音关', cc.SpriteFrame, function (err, spriteFrame) {
  21. self.node.getChildByName('Label').getComponent(cc.Sprite).spriteFrame = spriteFrame;
  22. });
  23. }
  24. },
  25. // called every frame
  26. update: function (dt) {
  27. },
  28. callback: function (event) {
  29. var self = this;
  30. if(Global.NoSound == false){
  31. cc.audioEngine.pauseAll();
  32. Global.NoSound = true;
  33. cc.loader.loadRes('texture/声音关', cc.SpriteFrame, function (err, spriteFrame) {
  34. self.node.getChildByName('Label').getComponent(cc.Sprite).spriteFrame = spriteFrame;
  35. });
  36. }else{
  37. Global.NoSound = false;
  38. Audio.playeffect('resources/audio/sound_click.mp3');
  39. cc.audioEngine.resumeAll();
  40. cc.loader.loadRes('texture/声音开', cc.SpriteFrame, function (err, spriteFrame) {
  41. self.node.getChildByName('Label').getComponent(cc.Sprite).spriteFrame = spriteFrame;
  42. });
  43. }
  44. //cc.find('Canvas/ChouseStyle').active = true;
  45. }
  46. });