Merge pull request #480 from knoxHuang/v1.0

add ParticleSystem APi
This commit is contained in:
Jare Guo
2016-03-16 13:56:29 +08:00
+180 -63
View File
@@ -25,42 +25,55 @@
var BlendFactor = cc.BlendFunc.BlendFactor;
/**
* Enum for emitter modes
* @enum EmitterMode
* @namespace ParticleSystem
* !#en Enum for emitter modes
* !#zh 发射模式
* @enum ParticleSystem.EmitterMode
*/
var EmitterMode = cc.Enum({
/**
* @property {Number} GRAVITY - Uses gravity, speed, radial and tangential acceleration.
* !#en Uses gravity, speed, radial and tangential acceleration.
* !#zh 重力模式,模拟重力,可让粒子围绕一个中心点移近或移远。
* @property {Number} GRAVITY
*/
GRAVITY: 0,
/**
* !#en Uses radius movement + rotation.
* !#zh 半径模式,可以使粒子以圆圈方式旋转,它也可以创造螺旋效果让粒子急速前进或后退。
* @property {Number} RADIUS - Uses radius movement + rotation.
*/
RADIUS: 1
});
/**
* Enum for particles movement type
* @enum PositionType
* @namespace ParticleSystem
* !#en Enum for particles movement type.
* !#zh 粒子位置类型
* @enum ParticleSystem.PositionType
*/
var PositionType = cc.Enum({
/**
* !#en
* Living particles are attached to the world and are unaffected by emitter repositioning.
* !#zh
* 自由模式,相对于世界坐标,不会随粒子节点移动而移动。(可产生火焰、蒸汽等效果)
* @property {Number} FREE
*/
FREE: 0,
/**
* !#en
* Living particles are attached to the world but will follow the emitter repositioning.<br/>
* Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.
* !#zh
* 相对模式,粒子会随父节点移动而移动,可用于制作移动角色身上的特效等等。(该选项在 Creator 中暂时不支持)
* @property {Number} RELATIVE
*/
RELATIVE: 1,
/**
* !#en
* Living particles are attached to the emitter and are translated along with it.
* !#zh
* 整组模式,粒子跟随发射器移动。(不会发生拖尾)
* @property {Number} GROUPED
*/
GROUPED: 2
@@ -73,7 +86,8 @@ var PositionType = cc.Enum({
var properties = {
/**
* Play particle in edit mode.
* !#en Play particle in edit mode.
* !#zh 在编辑器模式下预览粒子,启用后选中粒子时,粒子将自动播放。
* @property {Boolean} preview
* @default false
*/
@@ -91,7 +105,9 @@ var properties = {
},
/**
* !#en
* If set custom to true, then use custom properties insteadof read particle file.
* !#zh 是否自定义粒子属性。
* @property {Boolean} custom
* @default false
*/
@@ -122,7 +138,8 @@ var properties = {
},
/**
* The plist file.
* !#en The plist file.
* !#zh plist 格式的粒子配置文件。
* @property {string} file
* @default ""
*/
@@ -154,7 +171,9 @@ var properties = {
},
/**
* @property {Texture2D} texture - Texture of Particle System.
* !#en Texture of Particle System。
* !#zh 粒子贴图。
* @property {Texture2D} texture.
*/
_texture: {
default: '',
@@ -172,7 +191,9 @@ var properties = {
},
/**
* @property {Number} particleCount - Current quantity of particles that are being simulated.
* !#en Current quantity of particles that are being simulated.
* !#zh 当前播放的粒子数量。
* @property {Number} particleCount
*/
particleCount: {
get: function () {
@@ -185,7 +206,8 @@ var properties = {
},
/**
* specify the source Blend Factor
* !#en Specify the source Blend Factor.
* !#zh 指定原图混合模式。
* @property srcBlendFactor
* @type {BlendFactor}
*/
@@ -204,7 +226,8 @@ var properties = {
},
/**
* specify the destination Blend Factor
* !#en Specify the destination Blend Factor.
* !#zh 指定目标的混合模式。
* @property dstBlendFactor
* @type {BlendFactor}
*/
@@ -224,7 +247,7 @@ var properties = {
/**
* !#en If set to true, the particle system will automatically start playing on onLoad.
* !#zh 如果设置为true 运行时会自动发射粒子
* !#zh 如果设置为 true 运行时会自动发射粒子。
* @property playOnLoad
* @type {boolean}
* @default true
@@ -232,7 +255,9 @@ var properties = {
playOnLoad: true,
/**
* @property {Boolean} autoRemoveOnFinish - Indicate whether the owner node will be auto-removed when it has no particles left.
* !#en Indicate whether the owner node will be auto-removed when it has no particles left.
* !#zh 粒子播放完毕后自动销毁所在的节点。
* @property {Boolean} autoRemoveOnFinish
*/
_autoRemoveOnFinish: false,
autoRemoveOnFinish: {
@@ -251,7 +276,8 @@ var properties = {
},
/**
* Indicate whether the particle system is activated.
* !#en Indicate whether the particle system is activated.
* !#zh 是否激活粒子。
* @property {Boolean} active
* @readonly
*/
@@ -266,123 +292,167 @@ var properties = {
var CustomProps = (function () {
var DefaultValues = {
/**
* @property {Number} totalParticles - Maximum particles of the system.
* !#en Maximum particles of the system.
* !#zh 粒子最大数量。
* @property {Number} totalParticles
* @default 150
*/
totalParticles: 150,
/**
* @property {Number} duration - How many seconds the emitter wil run. -1 means 'forever'
* !#en How many seconds the emitter wil run. -1 means 'forever'.
* !#zh 发射器生存时间,单位秒,-1表示持续发射。
* @property {Number} duration
* @default ParticleSystem.DURATION_INFINITY
*/
duration: -1,
/**
* @property {Number} emissionRate - Emission rate of the particles.
* !#en Emission rate of the particles.
* !#zh 每秒发射的粒子数目。
* @property {Number} emissionRate
* @default 10
*/
emissionRate: 10,
/**
* @property {Number} life - Life of each particle setter.
* !#en Life of each particle setter.
* !#zh 粒子的运行时间。
* @property {Number} life
* @default 1
*/
life: 1,
/**
* @property {Number} lifeVar - Variation of life.
* !#en Variation of life.
* !#zh 粒子的运行时间变化范围。
* @property {Number} lifeVar
* @default 0
*/
lifeVar: 0,
/**
* @property {Color} startColor - Start color of each particle.
* !#en Start color of each particle.
* !#zh 粒子初始颜色。
* @property {Color} startColor
* @default cc.Color.WHITE
*/
startColor: cc.Color.WHITE,
/**
* @property {Color} startColorVar - Variation of the start color.
* !#en Variation of the start color.
* !#zh 粒子初始颜色变化范围。
* @property {Color} startColorVar
* @default cc.Color.BLACK
*/
startColorVar: cc.Color.BLACK,
/**
* @property {Color} endColor - Ending color of each particle.
* !#en Ending color of each particle.
* !#zh 粒子结束颜色。
* @property {Color} endColor
* @default new cc.Color(255, 255, 255, 0)
*/
endColor: cc.color(255, 255, 255, 0),
/**
* @property {Color} endColorVar - Variation of the end color.
* !#en Variation of the end color.
* !#zh 粒子结束颜色变化范围。
* @property {Color} endColorVar -
* @default Color.TRANSPARENT
*/
endColorVar: cc.color(0, 0, 0, 0),
/**
* @property {Number} angle - Angle of each particle setter.
* !#en Angle of each particle setter.
* !#zh 粒子角度。
* @property {Number} angle
* @default 90
*/
angle: 90,
/**
* @property {Number} angleVar - Variation of angle of each particle setter.
* !#en Variation of angle of each particle setter.
* !#zh 粒子角度变化范围。
* @property {Number} angleVar
* @default 20
*/
angleVar: 20,
/**
* @property {Number} startSize - Start size in pixels of each particle.
* !#en Start size in pixels of each particle.
* !#zh 粒子的初始大小。
* @property {Number} startSize
* @default 50
*/
startSize: 50,
/**
* @property {Number} startSizeVar - Variation of start size in pixels.
* !#en Variation of start size in pixels.
* !#zh 粒子初始大小的变化范围。
* @property {Number} startSizeVar
* @default 0
*/
startSizeVar: 0,
/**
* @property {Number} endSize - End size in pixels of each particle.
* !#en End size in pixels of each particle.
* !#zh 粒子结束时的大小。
* @property {Number} endSize
* @default 0
*/
endSize: 0,
/**
* @property {Number} endSizeVar - Variation of end size in pixels.
* !#en Variation of end size in pixels.
* !#zh 粒子结束大小的变化范围。
* @property {Number} endSizeVar
* @default 0
*/
endSizeVar: 0,
/**
* @property {Number} startSpin - Start angle of each particle.
* !#en Start angle of each particle.
* !#zh 粒子开始自旋角度。
* @property {Number} startSpin
* @default 0
*/
startSpin: 0,
/**
* @property {Number} startSpinVar - Variation of start angle.
* !#en Variation of start angle.
* !#zh 粒子开始自旋角度变化范围。
* @property {Number} startSpinVar
* @default 0
*/
startSpinVar: 0,
/**
* @property {Number} endSpin - End angle of each particle.
* !#en End angle of each particle.
* !#zh 粒子结束自旋角度。
* @property {Number} endSpin
* @default 0
*/
endSpin: 0,
/**
* @property {Number} endSpinVar - Variation of end angle.
* !#en Variation of end angle.
* !#zh 粒子结束自旋角度变化范围。
* @property {Number} endSpinVar
* @default 0
*/
endSpinVar: 0,
/**
* @property {Vec2} sourcePos - Source position of the emitter.
* !#en Source position of the emitter.
* !#zh 发射器位置。
* @property {Vec2} sourcePos
* @default cc.Vec2.ZERO
*/
sourcePos: cc.p(0, 0),
/**
* @property {Vec2} posVar - Variation of source position.
* !#en Variation of source position.
* !#zh 发射器位置的变化范围。(横向和纵向)
* @property {Vec2} posVar
* @default cc.Vec2.ZERO
*/
posVar: cc.p(0, 0),
/**
* Particles movement type.
* !#en Particles movement type.
* !#zh 粒子位置类型。
* @property {ParticleSystem.PositionType} positionType
* @default ParticleSystem.PositionType.FREE
*/
positionType: PositionType.FREE,
/**
* Particles emitter modes.
* !#en Particles emitter modes.
* !#zh 发射器类型。
* @property {ParticleSystem.EmitterMode} emitterMode
* @default ParticleSystem.EmitterMode.GRAVITY
*/
@@ -391,43 +461,59 @@ var CustomProps = (function () {
// GRAVITY MODE
/**
* @property {Vec2} gravity - Gravity of the emitter.
* !#en Gravity of the emitter.
* !#zh 重力。
* @property {Vec2} gravity
* @default cc.Vec2.ZERO
*/
gravity: cc.p(0, 0),
/**
* @property {Number} speed - Speed of the emitter.
* !#en Speed of the emitter.
* !#zh 速度。
* @property {Number} speed
* @default 180
*/
speed: 180,
/**
* @property {Number} speedVar - Variation of the speed.
* !#en Variation of the speed.
* !#zh 速度变化范围。
* @property {Number} speedVar
* @default 50
*/
speedVar: 50,
/**
* @property {Number} tangentialAccel - Tangential acceleration of each particle. Only available in 'Gravity' mode.
* !#en Tangential acceleration of each particle. Only available in 'Gravity' mode.
* !#zh 每个粒子的切向加速度,即垂直于重力方向的加速度,只有在重力模式下可用。
* @property {Number} tangentialAccel
* @default 80
*/
tangentialAccel: 80,
/**
* @property {Number} tangentialAccelVar - Variation of the tangential acceleration.
* !#en Variation of the tangential acceleration.
* !#zh 每个粒子的切向加速度变化范围。
* @property {Number} tangentialAccelVar
* @default 0
*/
tangentialAccelVar: 0,
/**
* @property {Number} radialAccel - Radial acceleration of each particle. Only available in 'Gravity' mode.
* !#en Acceleration of each particle. Only available in 'Gravity' mode.
* !#zh 粒子径向加速度,即平行于重力方向的加速度,只有在重力模式下可用。
* @property {Number} radialAccel
* @default 0
*/
radialAccel: 0,
/**
* @property {Number} radialAccelVar - Variation of the radial acceleration.
* !#en Variation of the radial acceleration.
* !#zh 粒子径向加速度变化范围。
* @property {Number} radialAccelVar
* @default 0
*/
radialAccelVar: 0,
/**
* @property {Boolean} rotationIsDir - Indicate whether the rotation of each particle equals to its direction. Only available in 'Gravity' mode.
* !#en Indicate whether the rotation of each particle equals to its direction. Only available in 'Gravity' mode.
* !#zh 每个粒子的旋转是否等于其方向,只有在重力模式下可用。
* @property {Boolean} rotationIsDir
* @default false
*/
rotationIsDir: false,
@@ -435,32 +521,44 @@ var CustomProps = (function () {
// RADIUS MODE
/**
* @property {Number} startRadius - Starting radius of the particles. Only available in 'Radius' mode.
* !#en Starting radius of the particles. Only available in 'Radius' mode.
* !#zh 初始半径,表示粒子出生时相对发射器的距离,只有在半径模式下可用。
* @property {Number} startRadius
* @default 0
*/
startRadius: 0,
/**
* @property {Number} startRadiusVar - Variation of the starting radius.
* !#en Variation of the starting radius.
* !#zh 初始半径变化范围。
* @property {Number} startRadiusVar
* @default 0
*/
startRadiusVar: 0,
/**
* @property {Number} endRadius - Ending radius of the particles. Only available in 'Radius' mode.
* !#en Ending radius of the particles. Only available in 'Radius' mode.
* !#zh 结束半径,只有在半径模式下可用。
* @property {Number} endRadius
* @default 0
*/
endRadius: 0,
/**
* @property {Number} endRadiusVar - Variation of the ending radius.
* !#en Variation of the ending radius.
* !#zh 结束半径变化范围。
* @property {Number} endRadiusVar
* @default 0
*/
endRadiusVar: 0,
/**
* @property {Number} rotatePerS - Number of degress to rotate a particle around the source pos per second. Only available in 'Radius' mode.
* !#en Number of degress to rotate a particle around the source pos per second. Only available in 'Radius' mode.
* !#zh 粒子每秒围绕起始点的旋转角度,只有在半径模式下可用。
* @property {Number} rotatePerS
* @default 0
*/
rotatePerS: 0,
/**
* @property {Number} rotatePerSVar - Variation of the degress to rotate a particle around the source pos per second.
* !#en Variation of the degress to rotate a particle around the source pos per second.
* !#zh 粒子每秒围绕起始点的旋转角度变化范围。
* @property {Number} rotatePerSVar
* @default 0
*/
rotatePerSVar: 0
@@ -583,7 +681,8 @@ var ParticleSystem = cc.Class({
statics: {
/**
* The Particle emitter lives forever
* !#en The Particle emitter lives forever.
* !#zh 表示发射器永久存在
* @property {Number} DURATION_INFINITY
* @default -1
* @static
@@ -592,7 +691,8 @@ var ParticleSystem = cc.Class({
DURATION_INFINITY: -1,
/**
* The starting size of the particle is equal to the ending size
* !#en The starting size of the particle is equal to the ending size.
* !#zh 表示粒子的起始大小等于结束大小。
* @property {Number} START_SIZE_EQUAL_TO_END_SIZE
* @default -1
* @static
@@ -601,7 +701,8 @@ var ParticleSystem = cc.Class({
START_SIZE_EQUAL_TO_END_SIZE: -1,
/**
* The starting radius of the particle is equal to the ending radius
* !#en The starting radius of the particle is equal to the ending radius.
* !#zh 表示粒子的起始半径等于结束半径。
* @property {Number} START_RADIUS_EQUAL_TO_END_RADIUS
* @default -1
* @static
@@ -701,7 +802,8 @@ var ParticleSystem = cc.Class({
// APIS
/**
* Add a particle to the emitter
* !#en Add a particle to the emitter.
* !#zh 添加一个粒子到发射器中。
* @method addParticle
* @return {Boolean}
*/
@@ -710,23 +812,32 @@ var ParticleSystem = cc.Class({
},
/**
* stop emitting particles. Running particles will continue to run until they die
* !#en Stop emitting particles. Running particles will continue to run until they die.
* !#zh 停止发射器发射粒子,发射出去的粒子将继续运行,直至粒子生命结束。
* @method stopSystem
* @example
* // stop particle system.
* myParticleSystem.stopSystem();
*/
stopSystem: function () {
this._sgNode.stopSystem();
},
/**
* Kill all living particles.
* !#en Kill all living particles.
* !#zh 杀死所有存在的粒子,然后重新启动粒子发射器。
* @method resetSystem
* @example
* // play particle system.
* myParticleSystem.resetSystem();
*/
resetSystem: function () {
this._sgNode.resetSystem();
},
/**
* whether or not the system is full
* !#en Whether or not the system is full.
* !#zh 发射器中粒子是否大于等于设置的总粒子数量。
* @method isFull
* @return {Boolean}
*/
@@ -735,9 +846,14 @@ var ParticleSystem = cc.Class({
},
/**
* !#en
* <p> Sets a new CCSpriteFrame as particle.</br>
* WARNING: this method is experimental. Use setTextureWithRect instead.
* </p>
* !#zh
* <p> 设置一个新的精灵帧为粒子。</br>
* 警告:这个函数只是试验,请使用 setTextureWithRect 实现。
* </p>
* @method setDisplayFrame
* @param {SpriteFrame} spriteFrame
*/
@@ -753,7 +869,8 @@ var ParticleSystem = cc.Class({
},
/**
* Sets a new texture with a rect. The rect is in Points.
* !#en Sets a new texture with a rect. The rect is in texture position and size.
* !#zh 设置一张新贴图和关联的矩形。
* @method setTextureWithRect
* @param {Texture2D} texture
* @param {Rect} rect
@@ -796,7 +913,7 @@ var ParticleSystem = cc.Class({
}
// recover sgNode properties
sgNode.setPosition(0, 0);
if (!active) {
@@ -808,7 +925,7 @@ var ParticleSystem = cc.Class({
}
//
if (done) {
done();
}