| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- // 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: {
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._init();
- },
- _addInfo : function(callback){
- cc.loader.loadRes("prefab/Info", function (err, texture) {
- this.info = cc.instantiate(texture);
- if (this.node.getChildByName(this.info.name)!=null) {
- this.node.getChildByName(this.info.name).destroy();
- }
- this.node.addChild(this.info);
- this.info.x = this._x;
- this.info.y = this._y;
- this.info.active = false;
- if (callback != null) {
- callback();
- }
- }.bind(this));
- },
- _addCoin : function(parent,callback){
- cc.loader.loadRes("prefab/coin", function (err, texture) {
- this.coin = cc.instantiate(texture);
- var tempNode = this.node;
- if (parent!=null) {
- tempNode = parent;
- }
- // cc.log('要被添加跳钱的 node',tempNode);
- if (tempNode.getChildByName(this.coin.name)!=null) {
- tempNode.getChildByName(this.coin.name).destroy();
- }
- tempNode.addChild(this.coin);
- this.coin.x = this._x;
- this.coin.y = this._y;
- this.coin.active = false;
- if (callback != null) {
- callback();
- }
- }.bind(this));
- },
- _addSmoke1 : function(callback){
- cc.loader.loadRes("prefab/particles/smoke", function (err, texture) {
- this.smoke1 = cc.instantiate(texture);
- this.smoke1.name = "smoke1";
- var tempNode = this.node;
- if (tempNode.getChildByName(this.smoke1.name)!=null) {
- tempNode.getChildByName(this.smoke1.name).destroy();
- }
- tempNode.addChild(this.smoke1);
- this.smoke1.x = this._x;
- this.smoke1.y = this._y;
- this.smoke1.active = false;
- if (callback != null) {
- callback();
- }
- }.bind(this));
- },
- _addSmoke2 : function(callback){
- cc.loader.loadRes("prefab/particles/smoke", function (err, texture) {
- this.smoke2 = cc.instantiate(texture);
- this.smoke2.name = "smoke2";
- var tempNode = this.node;
- if (tempNode.getChildByName(this.smoke2.name)!=null) {
- tempNode.getChildByName(this.smoke2.name).destroy();
- }
- tempNode.addChild(this.smoke2);
- this.smoke2.x = this._x;
- this.smoke2.y = this._y;
- this.smoke2.active = false;
- if (callback != null) {
- callback();
- }
- }.bind(this));
- },
- start() {
- // this.play();
- },
- _init: function () {
- //0 未播放 1正播放
- this.state = 0;
- this._x = 50;
- this._y = 100;
- this._coinX = 0;
- this._coinY = 200;
- },
- startPlay: function () {
- // this.callbackCountDownTime = function () {
- //
- // this.unschedule(this.callbackCountDownTime);
- //
- // }
- // this.schedule(this.callbackCountDownTime, 1);
- //
- //
- // this.callbackLoadScene = function () {
- // // cc.director.loadScene("game");
- // }
- // this.scheduleOnce(this.callbackLoadScene, 1);
- },
- playCoinAnim : function(count,parent){
- // console.log("我点了金币了吗" ,this.state,count);
- if (this.state == 0) {
- this.state = 1;
- this._addCoin(parent,function () {
- this.coin.active = true;
- this.Colortag = false;
- this.coin.opacity =255;
- this.coin.x = this._coinX;
- this.coin.y = this._coinY;
- var Label = this.getNode("Label",this.coin);
- Label.getComponent(cc.Label).string = count;
- var jump = cc.jumpBy(2, 0, 100, 50, 1);
- this.Colortag = true;
- var finished = cc.callFunc(function () {
- this.callbackstop = function () {
- this.coin.active = false;
- this.coin.stopAllActions();
- this.state = 0;
- };
- this.scheduleOnce(this.callbackstop, 1);
- }.bind(this));
- var sequence = cc.sequence(jump, finished);
- this.coin.runAction(sequence);
- }.bind(this));
- }
- },
- setCoinColor : function(){
- if (this.coin!=null) {
- if (this.Colortag) {
- if (this.coin.opacity<=0) {
- this.CoinColortag = false;
- }else{
- this.coin.opacity -=2;
- // console.log("都有什么 变了吗",this.coin);
- }
- }
- }
- },
- setSmokeColor : function(){
- if (this.smoke1!=null) {
- if (this.Colortag1) {
- if (this.smoke1.opacity<=0) {
- this.Colortag1 = false;
- }else{
- this.smoke1.opacity -=2.5;
- // console.log("都有什么 变了吗",this.coin);
- }
- }
- }
- if (this.smoke2!=null) {
- if (this.Colortag2) {
- if (this.smoke2.opacity<=0) {
- this.Colortag2 = false;
- }else{
- this.smoke2.opacity -=2.5;
- // console.log("都有什么 变了吗",this.coin);
- }
- }
- }
- },
- //开始播放的方法
- play: function () {
- if (this.state == 0) {
- this.state = 1;
- this._addInfo(function () {
- this.info.active = true;
- this.info.x = this._x;
- this.info.y = this._y;
- var jump = cc.jumpBy(2, 0, 0, 20, 3);
- var finished = cc.callFunc(function () {
- this.callbackstop = function () {
- this._reStop();
- }
- this.scheduleOnce(this.callbackstop, 1);
- }.bind(this));
- var sequence = cc.sequence(jump, finished);
- this.info.runAction(sequence);
- }.bind(this));
- }
- },
- //停止播放的方法
- stop: function () {
- this.state = 0;
- if (this.info!=null) {
- this.info.active = false;
- this.info.stopAllActions();
- this.unscheduleAllCallbacks();
- if (this.node.getChildByName(this.info.name)!=null) {
- this.node.getChildByName(this.info.name).destroy();
- }
- }
- },
- //内部调用的方法
- _reStop : function(){
- this.info.active = false;
- this.info.stopAllActions();
- this.callbackrestop = function () {
- this.state = 0;
- this.play();
- }.bind(this);
- this.scheduleOnce(this.callbackrestop, 1);
- },
- //开始播放的方法
- playSmoke: function () {
- if (this.state == 0) {
- this.state = 1;
- this._addSmoke1(function () {
- this.smoke1.active = true;
- this.smoke1.opacity =255;
- this.smoke1.x = this._x;
- this.smoke1.y = this._y;
- this.Colortag1 = false;
- var sc = cc.scaleTo(1,1.2,1.2);
- this.smoke1.runAction(sc);
- var jump = cc.jumpBy(1, 0, 150, 50, 1);
- this.Colortag1 = true;
- var finished = cc.callFunc(function () {
- this.callbackstopSmoke = function () {
- this._reStopSmoke();
- }
- this.scheduleOnce(this.callbackstopSmoke, 0.1);
- }.bind(this));
- var sequence = cc.sequence(jump, finished);
- this.smoke1.runAction(sequence);
- this.scheduleOnce(function () {
- this._addSmoke2(function () {
- this.smoke2.active = true;
- this.smoke2.opacity =255;
- this.smoke2.x = this._x;
- this.smoke2.y = this._y;
- this.Colortag2 = false;
- var sc = cc.scaleTo(1,1.2,1.2);
- this.smoke2.runAction(sc);
- var jump = cc.jumpBy(1, 0, 150, 50, 1);
- this.Colortag2 = true;
- var finished = cc.callFunc(function () {
- this.smoke2.active = false;
- }.bind(this));
- var sequence = cc.sequence(jump, finished);
- this.smoke2.runAction(sequence);
- }.bind(this))
- }.bind(this),0.75);
- }.bind(this));
- }
- },
- //停止播放的方法
- stopSmoke: function () {
- this.state = 0;
- if (this.smoke1!=null) {
- this.smoke1.active = false;
- this.smoke1.stopAllActions();
- this.smoke2.active = false;
- this.smoke2.stopAllActions();
- this.unscheduleAllCallbacks();
- if (this.smoke1.getChildByName(this.smoke1.name)!=null) {
- this.smoke1.getChildByName(this.smoke1.name).destroy();
- }
- if (this.smoke2.getChildByName(this.smoke2.name)!=null) {
- this.smoke2.getChildByName(this.smoke2.name).destroy();
- }
- }
- },
- //内部调用的方法
- _reStopSmoke : function(){
- this.smoke1.active = false;
- this.smoke1.stopAllActions();
- this.callbackrestopSmoke = function () {
- this.state = 0;
- this.playSmoke();
- }.bind(this);
- this.scheduleOnce(this.callbackrestopSmoke, 1);
- },
- loadImg: function (container, url, w, h) {
- cc.loader.load(url, function (err, texture) {
- var sprite = new cc.SpriteFrame(texture);
- container.getComponent(cc.Sprite).spriteFrame = sprite;
- if (w != null) {
- container.width = w;
- }
- if (h != null) {
- container.height = h;
- }
- });
- },
- getNode: function (name, parent) {
- if (parent == null) {
- return this.node.getChildByName(name);
- } else {
- return parent.getChildByName(name);
- }
- },
- update (dt) {
- this.setCoinColor();
- // this.setSmokeColor();
- },
- });
|