标签:游戏 cocos2d-x cocos2d-js 开发人员 c++
除了使用Cocos2d-JS的11种内置粒子系统外,我们还可以通过创建ParticleSystem对象,并设置属性实现自定义粒子系统,通过这种方式完全可以实现我们说需要的各种效果的粒子系统。使用ParticleSystem自定义粒子系统至少有两种方式可以实现:代码创建和plist文件创建。<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>angle</key> <real>270</real> <key>angleVariance</key> <real>5</real> <key>blendFuncDestination</key> <integer>771</integer> <key>blendFuncSource</key> <integer>1</integer> <key>duration</key> <real>-1</real> <key>emitterType</key> <real>0.0</real> <key>finishColorAlpha</key> <real>1</real> <key>finishColorBlue</key> <real>1</real> <key>finishColorGreen</key> <real>1</real> <key>finishColorRed</key> <real>1</real> <key>finishColorVarianceAlpha</key> <real>0.0</real> <key>finishColorVarianceBlue</key> <real>0.0</real> <key>finishColorVarianceGreen</key> <real>0.0</real> <key>finishColorVarianceRed</key> <real>0.0</real> <key>finishParticleSize</key> <real>-1</real> <key>finishParticleSizeVariance</key> <real>0.0</real> <key>gravityx</key> <real>0.0</real> <key>gravityy</key> <real>-10</real> <key>maxParticles</key> <real>700</real> <key>maxRadius</key> <real>0.0</real> <key>maxRadiusVariance</key> <real>0.0</real> <key>minRadius</key> <real>0.0</real> <key>minRadiusVariance</key> <real>0.0</real> <key>particleLifespan</key> <real>3</real> <key>particleLifespanVariance</key> <real>1</real> <key>radialAccelVariance</key> <real>0.0</real> <key>radialAcceleration</key> <real>1</real> <key>rotatePerSecond</key> <real>0.0</real> <key>rotatePerSecondVariance</key> <real>0.0</real> <key>rotationEnd</key> <real>0.0</real> <key>rotationEndVariance</key> <real>0.0</real> <key>rotationStart</key> <real>0.0</real> <key>rotationStartVariance</key> <real>0.0</real> <key>sourcePositionVariancex</key> <real>1200</real> <key>sourcePositionVariancey</key> <real>0.0</real> <key>speed</key> <real>130</real> <key>speedVariance</key> <real>30</real> <key>startColorAlpha</key> <real>1</real> <key>startColorBlue</key> <real>1</real> <key>startColorGreen</key> <real>1</real> <key>startColorRed</key> <real>1</real> <key>startColorVarianceAlpha</key> <real>0.0</real> <key>startColorVarianceBlue</key> <real>0.0</real> <key>startColorVarianceGreen</key> <real>0.0</real> <key>startColorVarianceRed</key> <real>0.0</real> <key>startParticleSize</key> <real>10</real> <key>startParticleSizeVariance</key> <real>5</real> <key>tangentialAccelVariance</key> <real>0.0</real> <key>tangentialAcceleration</key> <real>1</real> <key>textureFileName</key> <string>snow.png</string> </dict> </plist>在上述的plist文件描述的属性和属性值都是成对出现,其中<key>标签描述的是属性,<real>描述的属性值。
var HelloWorldLayer = cc.Layer.extend({ ctor: function () { ////////////////////////////// // 1. super init first this._super(); var size = cc.director.getWinSize(); var bg = new cc.Sprite("res/background-1.png"); bg.x = size.width / 2; bg.y = size.height / 2; this.addChild(bg); var particleSystem = new cc.ParticleSystem("res/snow.plist"); particleSystem.x = size.width / 2; particleSystem.y = size.height - 50; this.addChild(particleSystem); return true; } });
从代码可见plist文件创建粒子系统要比代码创建简单很多,这主要是因为采用了plist描述粒子属性。
《Cocos2d-x实战 JS卷》现已上线,各大商店均已开售:
京东:http://item.
标签:游戏 cocos2d-x cocos2d-js 开发人员 c++
原文地址:http://blog.csdn.net/tonny_guan/article/details/44915891