加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

CVP认证学习笔记--李天宇024粒子编辑器和粒子动画

发布时间:2020-12-14 17:06:38 所属栏目:百科 来源:网络整理
导读:本章节学习到了如何使用粒子系统,但是在开发的项目中,我们不会经常使用到,大多时候回将粒子转成帧动画进行播放,降低 IO 消耗,从而节约开发的成本。直接呈上代码: var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function () { this._supe

本章节学习到了如何使用粒子系统,但是在开发的项目中,我们不会经常使用到,大多时候回将粒子转成帧动画进行播放,降低IO消耗,从而节约开发的成本。直接呈上代码:

var HelloWorldLayer = cc.Layer.extend({

sprite:null,

ctor:function () {

this._super();

var size = cc.winSize;

var particle = ["爆炸粒子","火焰粒子","烟花粒子",

"花粒子","星系粒子","流星粒子",

"漩涡粒子","雪粒子","烟粒子",

"太阳粒子","雨粒子"];

var items = [];

for(var i=0;i<particle.length;i++){

var item = new cc.MenuItemFont(particle[i],this.callback,this);

item.setTag(i*10);

item.setPosition(size.width/2-100,size.height/2-30*i);

items.push(item);

}

var menu = new cc.Menu(items);

menu.setPosition(0,size.height/2-70);

this.addChild(menu);

return true;

},

callback: function (obj) {

var particle;

var size = cc.winSize;

switch(obj.tag){

case 0:

this.removeChildByTag(100);

particle = new cc.ParticleExplosion();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 10:

this.removeChildByTag(100);

particle = new cc.ParticleFire();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 20:

this.removeChildByTag(100);

particle = new cc.ParticleFireworks();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 30:

this.removeChildByTag(100);

particle = new cc.ParticleFlower();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 40:

this.removeChildByTag(100);

particle = new cc.ParticleGalaxy();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 50:

this.removeChildByTag(100);

particle = new cc.ParticleMeteor();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 60:

this.removeChildByTag(100);

particle = new cc.ParticleSpiral();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 70:

this.removeChildByTag(100);

particle = new cc.ParticleSnow();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 80:

this.removeChildByTag(100);

particle = new cc.ParticleSmoke();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 90:

this.removeChildByTag(100);

particle = new cc.ParticleSun();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

case 100:

this.removeChildByTag(100);

particle = new cc.ParticleRain();

particle.setTag(100);

particle.texture=cc.textureCache.addImage("res/ballfire.plist.png");

this.addChild(particle);

particle.setPosition(size.width/2+100,size.height/2);

break;

}

}

});

var HelloWorldScene = cc.Scene.extend({

onEnter:function () {

this._super();

var layer = new HelloWorldLayer();

this.addChild(layer);

}

});

上述是cocos2d自带的粒子系统,还可以自定义粒子系统,如:

//添加自定义粒子

cc.textureCache.addImage("res/ballfire.plist.png");

var myp=new cc.ParticleSystem("res/ballfire.plist");

this.addChild(myp);

myp.setPosition(cc.winSize.width/2,cc.winSize.height/2);

最后附上作业链接:

http://www.cocoscvp.com/usercode/2016_05_08/c4622e38f30a278640911f24977bc4e0735349ed/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读