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

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

概述本章节学习到了如何使用粒子系统,但是在开发的项目中,我们不会经常使用到,大多时候回将粒子转成帧动画进行播放,降低IO消耗,从而节约开发的成本。直接呈上代码: var HelloWorldLayer = cc.Layer.extend({    sprite:null,     ctor:function () {         this._super();         var size =

本章节学习到了如何使用粒子系统,但是在开发的项目中,我们不会经常使用到,大多时候回将粒子转成帧动画进行播放,降低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/

总结

以上是内存溢出为你收集整理的CVP认证学习笔记--李天宇024粒子编辑器和粒子动画全部内容,希望文章能够帮你解决CVP认证学习笔记--李天宇024粒子编辑器和粒子动画所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存