// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this ); // this.node.getChildByName("bg").getChildByName("share_btn").on('click', this.callback, this); this.node.getChildByName("bg").getChildByName("close_btn").on('click', this.callback, this); }, touchBegin: function(touch, envent) { }, callback: function(t) { window.Utils.playSound('sound/button' , 2, false); var name = t.node.name; if (name == "close_btn") { this.node.destroy(); } else if (name == "share_btn") { // if (cc.sys.platform == cc.sys.WECHAT_GAME) { // var titleStr = ""; // var img = ""; // if (window.Utils.probability(50)) { // titleStr = "震惊游戏内出现了神奇生物,究竟是什么!?"; // img = "share/img1.jpg"; // } else { // titleStr = "美人鱼到底是美人还是鱼?"; // img = "share/img2.jpg"; // } // cc.log("点击分享按钮"); // //主动拉起分享接口 // cc.loader.loadRes(img,function(err,data){ // wx.shareAppMessage({ // title: titleStr, // imageUrl: data.url, // success(res){ // console.log("转发成功!!!") // common.diamond += 20; // }, // fail(res){ // console.log("转发失败!!!") // }  // }) // }); // } return; } }, refresh: function(tag) { var bg = this.node.getChildByName("bg"); console.log("--tag---: " , tag , "--window.Config.fishing.name[tag];--: " , window.Config.fishing.name[tag]); bg.getChildByName("name").getComponent(cc.Label).string = window.Config.fishing.name[tag]; bg.getChildByName("des").getComponent(cc.Label).string = window.Config.fishing.des[tag]; var sprite = bg.getChildByName("fishingSp").getComponent(cc.Sprite); // node.removeComponent(cc.Sprite) // var sprite = node.addComponent(cc.Sprite); var path = 'fishing/fishing'+(tag +1); cc.resources.load(path, cc.SpriteFrame, function (err, spriteFrame) { console.log("path===", path, '====: ' , spriteFrame) if (err) { console.log(err.message || err); return; } sprite.spriteFrame = spriteFrame; }); // bg.getChildByName("fishingSp").getComponent(cc.Sprite).spriteFrame = cc.loader.getRes('fishing/fishing'+(tag +1)+ '.png', cc.SpriteFrame); }, // update (dt) {}, });