这里会不断更新记录我的Cocos2d-X lua学习笔记
1、触碰或滑动屏幕,产生星星例子特效
第一步:生成粒子特效plist文件,命名为touch.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>0</real> <key>angleVariance</key> <real>360</real> <key>blendFuncDestination</key> <integer>771</integer> <key>blendFuncSource</key> <integer>770</integer> <key>duration</key> <real>0.5</real> <key>emitterType</key> <real>0</real> <key>emissionRate</key> <real>1000</real> <key>finishColorAlpha</key> <real>0</real> <key>finishColorBlue</key> <real>1</real> <key>finishColorGreen</key> <real>1</real> <key>finishColorRed</key> <real>1</real> <key>finishColorVarianceAlpha</key> <real>1</real> <key>finishColorVarianceBlue</key> <real>0</real> <key>finishColorVarianceGreen</key> <real>0</real> <key>finishColorVarianceRed</key> <real>0</real> <key>rotationStart</key> <real>0</real> <key>rotationStartVariance</key> <real>0</real> <key>rotationEnd</key> <real>0</real> <key>rotationEndVariance</key> <real>0</real> <key>finishParticleSize</key> <real>15</real> <key>finishParticleSizeVariance</key> <real>2</real> <key>gravityx</key> <real>0</real> <key>gravityy</key> <real>0</real> <key>maxParticles</key> <real>30</real> <key>maxRadius</key> <real>0</real> <key>maxRadiusVariance</key> <real>0</real> <key>minRadius</key> <real>0</real> <key>minRadiusVariance</key> <real>10</real> <key>particleLifespan</key> <real>0.5</real> <key>particleLifespanVariance</key> <real>0</real> <key>radialAccelVariance</key> <real>0</real> <key>radialAcceleration</key> <real>100</real> <key>rotatePerSecond</key> <real>0</real> <key>rotatePerSecondVariance</key> <real>0</real> <key>sourcePositionVariancex</key> <real>0</real> <key>sourcePositionVariancey</key> <real>0</real> <key>sourcePositionx</key> <real>0</real> <key>sourcePositiony</key> <real>0</real> <key>speed</key> <real>20</real> <key>speedVariance</key> <real>0</real> <key>startColorAlpha</key> <real>0</real> <key>startColorBlue</key> <real>1</real> <key>startColorGreen</key> <real>1</real> <key>startColorRed</key> <real>1</real> <key>startColorVarianceAlpha</key> <real>1</real> <key>startColorVarianceBlue</key> <real>0</real> <key>startColorVarianceGreen</key> <real>0</real> <key>startColorVarianceRed</key> <real>0</real> <key>startParticleSize</key> <real>0</real> <key>startParticleSizeVariance</key> <real>8</real> <key>tangentialAccelVariance</key> <real>10</real> <key>tangentialAcceleration</key> <real>0</real> <key>textureFileName</key> <string>star.jpg</string> </dict> </plist>>
其中star.jpg是星星图片
emitter = cc.ParticleSystemQuad:create("touch.plist") emitter:setAnchorPoint(0,0) emitter:setPosition(px,py)把emitter加入到当前场景或图层中即可。
效果图: