SettingNode.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //通用设置界面
  2. var ZYGameTool = require('GameTool');
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. btn: {
  7. title: "按钮",
  8. type: cc.Node,
  9. default:[],
  10. },
  11. soundSp: {
  12. title: "音效开关",
  13. type: cc.Node,
  14. default:[],
  15. },
  16. musicSp: {
  17. title: "音乐开关",
  18. type: cc.Node,
  19. default:[],
  20. },
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad () {
  24. this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this);
  25. for (var i in this.btn){
  26. this.btn[i].on('click', function (event) {
  27. this.clickCall(event);
  28. }.bind(this));
  29. }
  30. },
  31. start () {
  32. this.init();
  33. },
  34. /**
  35. * 初始化当前设置状态
  36. */
  37. init() {
  38. this.soundSp[0].active = playeSound == 1;
  39. this.soundSp[1].active = playeSound == 0;
  40. this.musicSp[0].active = playeMusic == 1;
  41. this.musicSp[1].active = playeMusic == 0;
  42. },
  43. /**
  44. * 开关按钮
  45. * @param event
  46. */
  47. clickCall(event){
  48. var name = event.node.name.toString();
  49. if (name === "close"){
  50. this.closeWindos();
  51. return;
  52. }
  53. if (name === "soundBtn"){
  54. this.soundCall();
  55. } else if (name === "musicBtn"){
  56. this.musckCall();
  57. }
  58. this.saveData();
  59. },
  60. /**
  61. * 音效回调设置状态
  62. */
  63. soundCall: function(){
  64. playeSound = playeSound === 1 ? 0 : 1;
  65. this.soundSp[0].active = playeSound == 1;
  66. this.soundSp[1].active = playeSound == 0;
  67. },
  68. /**
  69. * 音乐回调设置状态
  70. */
  71. musckCall:function(){
  72. playeMusic = playeMusic === 1 ? 0 : 1;
  73. this.musicSp[0].active = playeMusic == 1;
  74. this.musicSp[1].active = playeMusic == 0;
  75. zy.isStopBgMusic();
  76. },
  77. /**
  78. * 保存数据到本地
  79. */
  80. saveData: function(){
  81. ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeSound, playeSound);//音效开关
  82. ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeMusic, playeMusic);//背景音乐开关
  83. },
  84. /**
  85. * 点击任意地方关闭当前窗口
  86. */
  87. closeWindos:function () {
  88. this.node.destroy();
  89. },
  90. touchBegin: function () {
  91. this.node.destroy();
  92. },
  93. // update (dt) {},
  94. });