SettingNode.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. ZYGameTool.getInstance().OpenAd("banner", "banner");
  31. },
  32. start () {
  33. this.init();
  34. },
  35. /**
  36. * 初始化当前设置状态
  37. */
  38. init() {
  39. this.soundSp[0].active = playeSound == 1;
  40. this.soundSp[1].active = playeSound == 0;
  41. this.musicSp[0].active = playeMusic == 1;
  42. this.musicSp[1].active = playeMusic == 0;
  43. },
  44. /**
  45. * 开关按钮
  46. * @param event
  47. */
  48. clickCall(event){
  49. var name = event.node.name.toString();
  50. if (name === "close"){
  51. this.closeWindos();
  52. return;
  53. }
  54. if (name === "soundBtn"){
  55. this.soundCall();
  56. } else if (name === "musicBtn"){
  57. this.musckCall();
  58. }
  59. this.saveData();
  60. },
  61. /**
  62. * 音效回调设置状态
  63. */
  64. soundCall: function(){
  65. playeSound = playeSound === 1 ? 0 : 1;
  66. this.soundSp[0].active = playeSound == 1;
  67. this.soundSp[1].active = playeSound == 0;
  68. },
  69. /**
  70. * 音乐回调设置状态
  71. */
  72. musckCall:function(){
  73. playeMusic = playeMusic === 1 ? 0 : 1;
  74. this.musicSp[0].active = playeMusic == 1;
  75. this.musicSp[1].active = playeMusic == 0;
  76. zy.isStopBgMusic();
  77. },
  78. /**
  79. * 保存数据到本地
  80. */
  81. saveData: function(){
  82. ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeSound, playeSound);//音效开关
  83. ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeMusic, playeMusic);//背景音乐开关
  84. },
  85. /**
  86. * 点击任意地方关闭当前窗口
  87. */
  88. closeWindos:function () {
  89. this.node.destroy();
  90. },
  91. touchBegin: function () {
  92. this.node.destroy();
  93. },
  94. // update (dt) {},
  95. });