Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!!

Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!!,第1张

概述Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!! 一种子d不过瘾 多来几种?我们准备了一个风格切换按钮,然后改写了fire var Airplane = cc.Layer.extend({ ctor:function (){//..... //有3种风格可以选择 me.bulletStyle=0; //添加子d风格,默认为0 var

Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!!

一种子d不过瘾 多来几种?我们准备了一个风格切换按钮,然后改写了fire

var Airplane = cc.Layer.extend({    ctor:function (){//.....      //有3种风格可以选择      me.bulletStyle=0; //添加子d风格,默认为0      var menu=new cc.Menu(new cc.MenuItemFont("子d风格",function(sender){        this.bulletStyle+=1;        if(this.bulletStyle>2){this.bulletStyle =0}      },me));      menu.setposition(size.wIDth - 100,15);      me.addChild(menu)//....      return true;    },fire:function(dt){      var me=this;      var point=me.air.getposition();      var newbullet=function(px,py,dx){        var sp=new cc.Sprite(this.batchNode.getTexture());        sp.setposition(px,py);        var bID=this.bullteID++;        sp.setTag(bID);        this.addChild(sp,-1);        var flyLen= cc.winSize.height - py;        var duration = flyLen / this.bullteSpeed;        var k= (cc.winSize.height-py)*dx        var action=new cc.Sequence([          new cc.Moveto(duration,cc.p(px + k,cc.winSize.height )),new cc.CallFunc(function(bullet,ID){            delete this.bullets[ID];            this.removeChildByTag(ID);          },this,bID)        ]);        sp.runAction(action);        this.bullets[bID]=sp;      }.bind(me);      var px=point.x;      var py=point.y + me.air.getContentSize().height + 20;      switch(me.bulletStyle){        case 1:          newbullet(px-10,0);          newbullet(px+10,0);          break;        case 2:          newbullet(px-10,-0.2);          newbullet(px,0.2);        default:          newbullet(px,0);      }    }});
总结

以上是内存溢出为你收集整理的Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!!全部内容,希望文章能够帮你解决Cocos2d-x《雷电大战》(4)-策略模式实现不同子d切换!!所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1084304.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存