标签:c++ cocos2d-x cocos2d-js 开发人员 游戏
从类图中我们可以看到,Cocos2d-JS中有内置的11种粒子,这些粒子的属性都是预先定义好的,我们也可以在程序代码中单独修改某些属性,我们在上一节的实例中都已经实现了这些属性的设置。var MyActionLayer = cc.Layer.extend({ flagTag: 0, // 操作标志 pLabel: null, ① ctor: function (flagTag) { this._super(); this.flagTag = flagTag; cc.log("MyActionLayer init flagTag " + this.flagTag); var size = cc.director.getWinSize(); var backMenuItem = new cc.LabelBMFont("<Back", res.fnt_fnt); var backMenuItem = new cc.MenuItemLabel(backMenuItem, this.backMenu, this); backMenuItem.x = size.width - 100; backMenuItem.y = 100; var mn = cc.Menu.create(backMenuItem); mn.x = 0; mn.y = 0; mn.anchorX = 0.5; mn.anchorY = 0.5; this.addChild(mn); this.pLabel = new cc.LabelBMFont("", res.fnt_fnt); this.pLabel.x = size.width /2; this.pLabel.y = size.height - 50; this.addChild(this.pLabel, 3); return true; }, backMenu: function (sender) { cc.director.popScene(); }, onEnterTransitionDidFinish: function () { cc.log("Tag = " + this.flagTag); var sprite = this.getChildByTag(SP_TAG); var size = cc.director.getWinSize(); var system; switch (this.flagTag) { ② case ActionTypes.kExplosion: system = new cc.ParticleExplosion(); this.pLabel.setString("Explosion"); break; case ActionTypes.kFire: system = new cc.ParticleFire(); system.texture = cc.textureCache.addImage(res.s_fire); ③ this.pLabel.setString("Fire"); break; case ActionTypes.kFireworks: system = new cc.ParticleFireworks(); this.pLabel.setString("Fireworks"); break; case ActionTypes.kFlower: system = new cc.ParticleFlower(); this.pLabel.setString("Flower"); break; case ActionTypes.kGalaxy: system = new cc.ParticleGalaxy(); this.pLabel.setString("Galaxy"); break; case ActionTypes.kMeteor: system = new cc.ParticleMeteor(); this.pLabel.setString("Meteor"); break; case ActionTypes.kRain: system = new cc.ParticleRain(); this.pLabel.setString("Rain"); break; case ActionTypes.kSmoke: system = new cc.ParticleSmoke(); this.pLabel.setString("Smoke"); break; case ActionTypes.kSnow: system = new cc.ParticleSnow(); this.pLabel.setString("Snow"); break; case ActionTypes.kSpiral: system = new cc.ParticleSpiral(); this.pLabel.setString("Spiral"); break; case ActionTypes.kSun: system = new cc.ParticleSun(); this.pLabel.setString("Sun"); break; ④ } system.x = size.width /2; system.y = size.height /2; this.addChild(system); } }); var MyActionScene = cc.Scene.extend({ onEnter: function () { this._super(); } });
另外,如果在Web浏览器中运行还需要为粒子系统添加纹理,我们只在代码第③行添加了火粒子纹理,其它的粒子纹理添加类似。
《Cocos2d-x实战 JS卷》现已上线,各大商店均已开售:
京东:http://item.
标签:c++ cocos2d-x cocos2d-js 开发人员 游戏
原文地址:http://blog.csdn.net/tonny_guan/article/details/44904387