discover.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
  33. // this.node.getChildByName("bg").getChildByName("share_btn").on('click', this.callback, this);
  34. this.node.getChildByName("bg").getChildByName("close_btn").on('click', this.callback, this);
  35. },
  36. touchBegin: function(touch, envent) {
  37. },
  38. callback: function(t) {
  39. window.Utils.playSound('sound/button' , 2, false);
  40. var name = t.node.name;
  41. if (name == "close_btn") {
  42. this.node.destroy();
  43. } else if (name == "share_btn") {
  44. // if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  45. // var titleStr = "";
  46. // var img = "";
  47. // if (window.Utils.probability(50)) {
  48. // titleStr = "震惊游戏内出现了神奇生物,究竟是什么!?";
  49. // img = "share/img1.jpg";
  50. // } else {
  51. // titleStr = "美人鱼到底是美人还是鱼?";
  52. // img = "share/img2.jpg";
  53. // }
  54. // cc.log("点击分享按钮");
  55. // //主动拉起分享接口
  56. // cc.loader.loadRes(img,function(err,data){
  57. // wx.shareAppMessage({
  58. // title: titleStr,
  59. // imageUrl: data.url,
  60. // success(res){
  61. // console.log("转发成功!!!")
  62. // common.diamond += 20;
  63. // },
  64. // fail(res){
  65. // console.log("转发失败!!!")
  66. // } 
  67. // })
  68. // });
  69. // }
  70. return;
  71. }
  72. },
  73. refresh: function(tag) {
  74. var bg = this.node.getChildByName("bg");
  75. console.log("--tag---: " , tag , "--window.Config.fishing.name[tag];--: " , window.Config.fishing.name[tag]);
  76. bg.getChildByName("name").getComponent(cc.Label).string = window.Config.fishing.name[tag];
  77. bg.getChildByName("des").getComponent(cc.Label).string = window.Config.fishing.des[tag];
  78. var sprite = bg.getChildByName("fishingSp").getComponent(cc.Sprite);
  79. // node.removeComponent(cc.Sprite)
  80. // var sprite = node.addComponent(cc.Sprite);
  81. var path = 'fishing/fishing'+(tag +1);
  82. cc.resources.load(path, cc.SpriteFrame, function (err, spriteFrame) {
  83. console.log("path===", path, '====: ' , spriteFrame)
  84. if (err) {
  85. console.log(err.message || err);
  86. return;
  87. }
  88. sprite.spriteFrame = spriteFrame;
  89. });
  90. // bg.getChildByName("fishingSp").getComponent(cc.Sprite).spriteFrame = cc.loader.getRes('fishing/fishing'+(tag +1)+ '.png', cc.SpriteFrame);
  91. },
  92. // update (dt) {},
  93. });