01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
|
//创建一个CCParticleSystem粒子系统
CCParticleSystem* ignore = CCParticleSystemQuad::create(
"Particles/SmallSun.plist"
);
//第一种创建节点方式
CCNode *parent1 = CCNode::create();
//创建一个节点
//第二种创建节点方式
CCNode *parent2 = CCParticleBatchNode::create(ignore->getTexture());
//第一种:创建一个CCParticleSystemQuad系统:每个粒子用4个点(Quad,矩形)表示的粒子系统
CCParticleSystemQuad *emitter = CCParticleSystemQuad::create(
"Particles/SmallSun.plist"
);
//第二种:创建CCParticleSystemQuad系统
m_emitter =
new
CCParticleSystemQuad();
std::string filename =
"Particles/"
+“粒子资源文件名字”+
".plist"
;
m_emitter->initWithFile(filename.c_str());
|
下面是一些常用设置:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
emitter1->setStartColor(ccc4f(
1
,
0
,
0
,
1
));
//设置粒子RGBA值
emitter1->setBlendAdditive(
false
);
//是否添加混合
emitter1->setPosition(ccp( s.width/
2
-
30
, s.height/
2
+
60
*neg));
//设置发射粒子的位置
emitter->setAutoRemoveOnFinish(
true
);
//完成后制动移除
//将粒子系统添加到节点(也可以直接将其添加到一个背景精灵CCSprite里面)
parent1->addChild(emitter1,
0
,
1
);
//然后在添加到层里面
layer->addChild(parent1,
10
,
1000
+i);
CCParticleSystem中的常用设置参数表:
struct {
//重力和方向的向量
CCPoint gravity;
//速度
float
speed;
//粒子的速度差异
float
speedVar;
//粒子的切线加速度
float
tangentialAccel;
//粒子间的切线加速度差异
float
tangentialAccelVar;
//粒子的径向加速度
float
radialAccel;
//粒子间的径向加速度差异
float
radialAccelVar;
} modeA;
struct {
//粒子开始半径
float
startRadius;
//粒子间开始半径差异
float
startRadiusVar;
//粒子结束半径
float
endRadius;
//粒子间结束半径差异
float
endRadiusVar;
//粒子每秒的旋转角度
float
rotatePerSecond;
//粒子间每秒的旋转角度差异
float
rotatePerSecondVar;
} modeB;
|
cocos2dx已经为我们提供了非常多的粒子系统效果:
01
02
03
04
05
06
07
08
09
10
11
|
CCParticleExplosion爆炸
CCParticleFire 火
CCParticleFireworks烟火
CCParticleFlower花
CCParticleGalaxy 银河
CCParticleMeteor 流行
CCParticleRain 下雨
CCParticleSmoke 下雪
CCParticleSnow 炊烟
CCParticleSpiral 螺旋
CCParticleSun 太阳焰
|
Cocos2d-x初入学堂(1)---图形绘制
http://www.eoeandroid.com/thread-212255-1-1.html
Cocos2d-x初入学堂(2)-->CCSprite基本处理
http://www.eoeandroid.com/thread-212285-1-1.html
Cocos2d-x初入学堂(3)-->TexturePacker非常棒的图像处理工具
http://www.eoeandroid.com/thread-212558-1-1.html
Cocos2d-x初入学堂(4)-->CCSprite动画
http://www.eoeandroid.com/thread-212564-1-1.html
Cocos2d-x初入学堂(5)-->CCMenuItem菜单项
http://www.eoeandroid.com/thread-212567-1-1.html
Cocos2d-x初入学堂(6)-->Bitmap Font generator位图字体工具
http://www.eoeandroid.com/thread-212570-1-1.html
Cocos2d-x初入学堂(7)-->win32显示中文乱码解决方法
http://www.eoeandroid.com/thread-212578-1-1.html
Cocos2d-x初入学堂(8)-->CCLabel菜单项
http://www.eoeandroid.com/thread-225554-1-1.html
Cocos2d-x初入学堂(9)-->CCParticleSystem粒子系统
http://www.eoeandroid.com/thread-225561-1-1.html
Cocos2d-x初入学堂(10)-->ParticleEditor粒子编辑器
http://www.eoeandroid.com/thread-225570-1-1.html
Cocos2d-x初入学堂(11)-->CCScene场景切换
http://www.eoeandroid.com/thread-225574-1-1.html
Cocos2d-x初入学堂(12)-->CCTMXTiledMap和CCTileMapAtlas拼地图
http://www.eoeandroid.com/thread-225577-1-1.html
Cocos2d-x初入学堂(13)-->Tiled Map Editor地图编辑器
http://www.eoeandroid.com/thread-225870-1-1.html
Cocos2d-x初入学堂(14)-->触屏事件
http://www.eoeandroid.com/thread-225876-1-1.html
Cocos2d-x初入学堂(15)-->背景音乐和音效
http://www.eoeandroid.com/thread-225877-1-1.html