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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值