2012-08-29 17:17:36 +08:00
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
local SceneIdx = -1
|
2012-08-29 17:17:36 +08:00
|
|
|
local MAX_LAYER = 42
|
|
|
|
|
|
|
|
local emitter = nil
|
|
|
|
local background = nil
|
|
|
|
|
|
|
|
local labelAtlas = nil
|
|
|
|
local titleLabel = nil
|
|
|
|
local subtitleLabel = nil
|
2012-08-30 16:38:16 +08:00
|
|
|
local baseLayer_entry = nil
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
local function backAction()
|
2012-08-29 17:17:36 +08:00
|
|
|
SceneIdx = SceneIdx - 1
|
|
|
|
if SceneIdx < 0 then
|
|
|
|
SceneIdx = SceneIdx + MAX_LAYER
|
|
|
|
end
|
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
return CreateParticleLayer()
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
local function restartAction()
|
|
|
|
return CreateParticleLayer()
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
local function nextAction()
|
2012-08-29 17:17:36 +08:00
|
|
|
SceneIdx = SceneIdx + 1
|
|
|
|
SceneIdx = math.mod(SceneIdx, MAX_LAYER)
|
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
return CreateParticleLayer()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function backCallback(sender)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2012-08-30 15:32:29 +08:00
|
|
|
|
|
|
|
scene:addChild(backAction())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
2012-08-30 15:32:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function restartCallback(sender)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2012-08-30 15:32:29 +08:00
|
|
|
|
|
|
|
scene:addChild(restartAction())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
2012-08-30 15:32:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function nextCallback(sender)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2012-08-30 15:32:29 +08:00
|
|
|
|
|
|
|
scene:addChild(nextAction())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function toggleCallback(sender)
|
|
|
|
if emitter ~= nil then
|
2013-08-20 13:44:37 +08:00
|
|
|
if emitter:getPositionType() == cc.POSITION_TYPE_GROUPED then
|
|
|
|
emitter:setPositionType(cc.POSITION_TYPE_FREE)
|
|
|
|
elseif emitter:getPositionType() == cc.POSITION_TYPE_FREE then
|
|
|
|
emitter:setPositionType(cc.POSITION_TYPE_RELATIVE)
|
|
|
|
elseif emitter:getPositionType() == cc.POSITION_TYPE_RELATIVE then
|
|
|
|
emitter:setPositionType(cc.POSITION_TYPE_GROUPED)
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-30 16:38:16 +08:00
|
|
|
local function setEmitterPosition()
|
|
|
|
if emitter ~= nil then
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setPosition(s.width / 2, s.height / 2)
|
2012-08-30 16:38:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function update(dt)
|
|
|
|
if emitter ~= nil then
|
|
|
|
local str = "" .. emitter:getParticleCount()
|
2013-03-05 14:46:18 +08:00
|
|
|
-- labelAtlas:setString("" .. str)
|
2012-08-30 16:38:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function baseLayer_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-30 16:38:16 +08:00
|
|
|
baseLayer_entry = scheduler:scheduleScriptFunc(update, 0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-30 16:38:16 +08:00
|
|
|
scheduler:unscheduleScriptEntry(baseLayer_entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-29 17:17:36 +08:00
|
|
|
local function getBaseLayer()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.LayerColor:create(cc.c4b(127,127,127,255))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
emitter = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
titleLabel = cc.LabelTTF:create("", "Arial", 28)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(titleLabel, 100, 1000)
|
|
|
|
titleLabel:setPosition(s.width / 2, s.height - 50)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
subtitleLabel = cc.LabelTTF:create("", "Arial", 16)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(subtitleLabel, 100)
|
|
|
|
subtitleLabel:setPosition(s.width / 2, s.height - 80)
|
|
|
|
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
|
|
|
local item4 = cc.MenuItemToggle:create(cc.MenuItemFont:create("Free Movement"))
|
|
|
|
item4:addSubItem(cc.MenuItemFont:create("Relative Movement"))
|
|
|
|
item4:addSubItem(cc.MenuItemFont:create("Grouped Movement"))
|
2012-09-11 17:13:20 +08:00
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
item4:registerScriptTapHandler(toggleCallback)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
|
|
|
menu:addChild(item4)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition(cc.p(0, 0))
|
|
|
|
item1:setPosition(cc.p(s.width/2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
|
|
|
item2:setPosition(cc.p(s.width/2, item2:getContentSize().height / 2))
|
|
|
|
item3:setPosition(cc.p(s.width/2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
|
|
|
item4:setPosition(cc.p(0, 100))
|
|
|
|
item4:setAnchorPoint(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
layer:addChild(menu, 100)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
labelAtlas = cc.LabelAtlas:_create("0000", "fps_images.png", 12, 32, string.byte('.'))
|
2012-08-30 16:38:16 +08:00
|
|
|
layer:addChild(labelAtlas, 100)
|
2013-08-20 13:44:37 +08:00
|
|
|
labelAtlas:setPosition(cc.p(s.width - 66, 50))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- moving background
|
2013-08-20 13:44:37 +08:00
|
|
|
background = cc.Sprite:create(s_back3)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(background, 5)
|
2013-08-20 13:44:37 +08:00
|
|
|
background:setPosition(cc.p(s.width / 2, s.height - 180))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local move = cc.MoveBy:create(4, cc.p(300, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
local move_back = move:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create(move, move_back)
|
|
|
|
background:runAction(cc.RepeatForever:create(seq))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
local function onTouchEnded(x, y)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pos = cc.p(0, 0)
|
2012-08-29 17:17:36 +08:00
|
|
|
if background ~= nil then
|
2013-08-20 13:44:37 +08:00
|
|
|
pos = background:convertToWorldSpace(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if emitter ~= nil then
|
2013-08-20 13:44:37 +08:00
|
|
|
local newPos = cc.pSub(cc.p(x, y), pos)
|
2012-08-30 16:38:16 +08:00
|
|
|
emitter:setPosition(newPos.x, newPos.y)
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTouch(eventType, x, y)
|
2013-03-05 14:46:18 +08:00
|
|
|
if eventType == "began" then
|
2012-08-30 16:38:16 +08:00
|
|
|
return true
|
2012-08-29 17:17:36 +08:00
|
|
|
else
|
|
|
|
return onTouchEnded(x, y)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
layer:setTouchEnabled(true)
|
|
|
|
layer:registerScriptTouchHandler(onTouch)
|
2012-08-30 16:38:16 +08:00
|
|
|
layer:registerScriptHandler(baseLayer_onEnterOrExit)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- ParticleReorder
|
|
|
|
---------------------------------
|
|
|
|
local ParticleReorder_Order = nil
|
|
|
|
local ParticleReorder_entry = nil
|
|
|
|
local ParticleReorder_layer = nil
|
|
|
|
|
|
|
|
local function reorderParticles(dt)
|
2012-08-30 16:38:16 +08:00
|
|
|
update(dt)
|
|
|
|
|
2012-08-29 17:17:36 +08:00
|
|
|
for i = 0, 1 do
|
|
|
|
local parent = ParticleReorder_layer:getChildByTag(1000 + i)
|
|
|
|
local child1 = parent:getChildByTag(1)
|
|
|
|
local child2 = parent:getChildByTag(2)
|
|
|
|
local child3 = parent:getChildByTag(3)
|
|
|
|
|
|
|
|
if math.mod(ParticleReorder_Order, 3) == 0 then
|
|
|
|
parent:reorderChild(child1, 1)
|
|
|
|
parent:reorderChild(child2, 2)
|
|
|
|
parent:reorderChild(child3, 3)
|
|
|
|
|
|
|
|
elseif math.mod(ParticleReorder_Order, 3) == 1 then
|
|
|
|
parent:reorderChild(child1, 3)
|
|
|
|
parent:reorderChild(child2, 1)
|
|
|
|
parent:reorderChild(child3, 2)
|
|
|
|
|
|
|
|
elseif math.mod(ParticleReorder_Order, 3) == 2 then
|
|
|
|
parent:reorderChild(child1, 2)
|
|
|
|
parent:reorderChild(child2, 3)
|
|
|
|
parent:reorderChild(child3, 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ParticleReorder_Order = ParticleReorder_Order + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ParticleReorder_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-29 17:17:36 +08:00
|
|
|
ParticleReorder_entry = scheduler:scheduleScriptFunc(reorderParticles, 1.0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-29 17:17:36 +08:00
|
|
|
scheduler:unscheduleScriptEntry(ParticleReorder_entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ParticleReorder()
|
|
|
|
ParticleReorder_layer = getBaseLayer()
|
|
|
|
|
|
|
|
ParticleReorder_Order = 0
|
2013-08-20 13:44:37 +08:00
|
|
|
ParticleReorder_layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
ParticleReorder_layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local ignore = cc.ParticleSystemQuad:create("Particles/SmallSun.plist")
|
|
|
|
local parent1 = cc.Node:create()
|
|
|
|
local parent2 = cc.ParticleBatchNode:createWithTexture(ignore:getTexture())
|
2012-08-29 17:17:36 +08:00
|
|
|
ignore:unscheduleUpdate()
|
|
|
|
|
|
|
|
for i = 0, 1 do
|
|
|
|
local parent = nil
|
|
|
|
if i == 0 then
|
|
|
|
parent = parent1
|
|
|
|
else
|
|
|
|
parent = parent2
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local emitter1 = cc.ParticleSystemQuad:create("Particles/SmallSun.plist")
|
|
|
|
emitter1:setStartColor(cc.c4f(1,0,0,1))
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter1:setBlendAdditive(false)
|
2013-08-20 13:44:37 +08:00
|
|
|
local emitter2 = cc.ParticleSystemQuad:create("Particles/SmallSun.plist")
|
|
|
|
emitter2:setStartColor(cc.c4f(0,1,0,1))
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter2:setBlendAdditive(false)
|
2013-08-20 13:44:37 +08:00
|
|
|
local emitter3 = cc.ParticleSystemQuad:create("Particles/SmallSun.plist")
|
|
|
|
emitter3:setStartColor(cc.c4f(0,0,1,1))
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter3:setBlendAdditive(false)
|
|
|
|
|
|
|
|
local neg = nil
|
|
|
|
if i == 0 then
|
|
|
|
neg = 1
|
|
|
|
else
|
|
|
|
neg = -1
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter1:setPosition(cc.p( s.width / 2 - 30, s.height / 2 + 60 * neg))
|
|
|
|
emitter2:setPosition(cc.p( s.width / 2, s.height / 2 + 60 * neg))
|
|
|
|
emitter3:setPosition(cc.p( s.width / 2 + 30, s.height / 2 + 60 * neg))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
parent:addChild(emitter1, 0, 1)
|
|
|
|
parent:addChild(emitter2, 0, 2)
|
|
|
|
parent:addChild(emitter3, 0, 3)
|
|
|
|
|
|
|
|
ParticleReorder_layer:addChild(parent, 10, 1000 + i)
|
|
|
|
end
|
|
|
|
|
|
|
|
ParticleReorder_layer:registerScriptHandler(ParticleReorder_onEnterOrExit)
|
|
|
|
|
|
|
|
titleLabel:setString("Reordering particles")
|
|
|
|
subtitleLabel:setString("Reordering particles with and without batches batches")
|
|
|
|
return ParticleReorder_layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- ParticleBatchHybrid
|
|
|
|
---------------------------------
|
|
|
|
local ParticleBatchHybrid_entry = nil
|
|
|
|
local ParticleBatchHybrid_parent1 = nil
|
|
|
|
local ParticleBatchHybrid_parent2 = nil
|
|
|
|
|
|
|
|
local function switchRender(dt)
|
2012-08-30 16:38:16 +08:00
|
|
|
update(dt)
|
|
|
|
|
2012-08-29 17:17:36 +08:00
|
|
|
local cond = (emitter:getBatchNode() ~= nil)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:removeFromParent(false)
|
2012-08-29 17:17:36 +08:00
|
|
|
local str = "Particle: Using new parent: "
|
|
|
|
local newParent = nil
|
|
|
|
if cond == true then
|
|
|
|
newParent = ParticleBatchHybrid_parent2
|
2013-08-20 13:44:37 +08:00
|
|
|
str = str .. "Node"
|
2012-08-29 17:17:36 +08:00
|
|
|
else
|
|
|
|
newParent = ParticleBatchHybrid_parent1
|
2013-08-20 13:44:37 +08:00
|
|
|
str = str .. "ParticleBatchNode"
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
newParent:addChild(emitter)
|
|
|
|
cclog(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ParticleBatchHybrid_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-29 17:17:36 +08:00
|
|
|
ParticleBatchHybrid_entry = scheduler:scheduleScriptFunc(switchRender, 2.0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-29 17:17:36 +08:00
|
|
|
scheduler:unscheduleScriptEntry(ParticleBatchHybrid_entry)
|
|
|
|
--emitter:release()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ParticleBatchHybrid()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:create("Particles/LavaFlow.plist")
|
2012-08-29 17:17:36 +08:00
|
|
|
---- emitter:retain()
|
2013-08-20 13:44:37 +08:00
|
|
|
local batch = cc.ParticleBatchNode:createWithTexture(emitter:getTexture())
|
2012-08-29 17:17:36 +08:00
|
|
|
batch:addChild(emitter)
|
|
|
|
layer:addChild(batch, 10)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local node = cc.Node:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(node)
|
|
|
|
ParticleBatchHybrid_parent1 = batch
|
|
|
|
ParticleBatchHybrid_parent2 = node
|
|
|
|
|
|
|
|
layer:registerScriptHandler(ParticleBatchHybrid_onEnterOrExit)
|
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
titleLabel:setString("Particle Batch")
|
2012-08-29 17:17:36 +08:00
|
|
|
subtitleLabel:setString("Hybrid: batched and non batched every 2 seconds")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- ParticleBatchMultipleEmitters
|
|
|
|
---------------------------------
|
|
|
|
local function ParticleBatchMultipleEmitters()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local emitter1 = cc.ParticleSystemQuad:create("Particles/LavaFlow.plist")
|
|
|
|
emitter1:setStartColor(cc.c4f(1,0,0,1))
|
|
|
|
local emitter2 = cc.ParticleSystemQuad:create("Particles/LavaFlow.plist")
|
|
|
|
emitter2:setStartColor(cc.c4f(0,1,0,1))
|
|
|
|
local emitter3 = cc.ParticleSystemQuad:create("Particles/LavaFlow.plist")
|
|
|
|
emitter3:setStartColor(cc.c4f(0,0,1,1))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter1:setPosition(cc.p(s.width / 1.25, s.height / 1.25))
|
|
|
|
emitter2:setPosition(cc.p(s.width / 2, s.height / 2))
|
|
|
|
emitter3:setPosition(cc.p(s.width / 4, s.height / 4))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local batch = cc.ParticleBatchNode:createWithTexture(emitter1:getTexture())
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
batch:addChild(emitter1, 0)
|
|
|
|
batch:addChild(emitter2, 0)
|
|
|
|
batch:addChild(emitter3, 0)
|
|
|
|
|
|
|
|
layer:addChild(batch, 10)
|
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
titleLabel:setString("Particle Batch")
|
2012-08-29 17:17:36 +08:00
|
|
|
subtitleLabel:setString("Multiple emitters. One Batch")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoFlower
|
|
|
|
---------------------------------
|
|
|
|
local function DemoFlower()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleFlower:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleFlower")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoGalaxy
|
|
|
|
---------------------------------
|
|
|
|
local function DemoGalaxy()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleGalaxy:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleGalaxy")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoFirework
|
|
|
|
---------------------------------
|
|
|
|
local function DemoFirework()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleFireworks:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleFireworks")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoSpiral
|
|
|
|
---------------------------------
|
|
|
|
local function DemoSpiral()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSpiral:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleSpiral")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoSun
|
|
|
|
---------------------------------
|
|
|
|
local function DemoSun()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSun:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleSun")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoMeteor
|
|
|
|
---------------------------------
|
|
|
|
local function DemoMeteor()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleMeteor:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleMeteor")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoFire
|
|
|
|
---------------------------------
|
|
|
|
local function DemoFire()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleFire:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2013-08-23 16:12:59 +08:00
|
|
|
local pos_x, pos_y = emitter:getPosition()
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setPosition(pos_x, 100)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
titleLabel:setString("ParticleFire")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoSmoke
|
|
|
|
---------------------------------
|
|
|
|
local function DemoSmoke()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSmoke:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2013-08-23 16:12:59 +08:00
|
|
|
local pos_x, pos_y = emitter:getPosition()
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setPosition(pos_x, 100)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleSmoke")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoExplosion
|
|
|
|
---------------------------------
|
|
|
|
local function DemoExplosion()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleExplosion:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setAutoRemoveOnFinish(true)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleExplosion")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoSnow
|
|
|
|
---------------------------------
|
|
|
|
local function DemoSnow()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSnow:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2013-08-23 16:12:59 +08:00
|
|
|
local pos_x, pos_y = emitter:getPosition()
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setPosition(pos_x, pos_y - 110)
|
|
|
|
emitter:setLife(3)
|
|
|
|
emitter:setLifeVar(1)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setGravity(cc.p(0, -10))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- speed of particles
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setSpeed(130)
|
|
|
|
emitter:setSpeedVar(30)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
local startColor = emitter:getStartColor()
|
2012-08-29 17:17:36 +08:00
|
|
|
startColor.r = 0.9
|
|
|
|
startColor.g = 0.9
|
|
|
|
startColor.b = 0.9
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setStartColor(startColor)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
local startColorVar = emitter:getStartColorVar()
|
2012-08-29 17:17:36 +08:00
|
|
|
startColorVar.b = 0.1
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setStartColorVar(startColorVar)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_snow))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleSnow")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoRain
|
|
|
|
---------------------------------
|
|
|
|
local function DemoRain()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleRain:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2013-08-23 16:12:59 +08:00
|
|
|
local pos_x, pos_y = emitter:getPosition()
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setPosition(pos_x, pos_y - 100)
|
|
|
|
emitter:setLife(4)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleRain")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoBigFlower
|
|
|
|
---------------------------------
|
|
|
|
local function DemoBigFlower()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(50)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
background:addChild(emitter, 10)
|
|
|
|
----emitter:release() -- win32 : use this line or remove this line and use autorelease()
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture( cc.TextureCache:getInstance():addImage(s_stars1) )
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter:setDuration(-1)
|
|
|
|
|
|
|
|
-- gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setGravity(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(90)
|
|
|
|
emitter:setAngleVar(360)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
emitter:setSpeed(160)
|
|
|
|
emitter:setSpeedVar(20)
|
|
|
|
|
|
|
|
-- radial
|
|
|
|
emitter:setRadialAccel(-120)
|
|
|
|
emitter:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- tagential
|
|
|
|
emitter:setTangentialAccel(30)
|
|
|
|
emitter:setTangentialAccelVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(160, 240)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(4)
|
|
|
|
emitter:setLifeVar(1)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
emitter:setStartSpin(0)
|
|
|
|
emitter:setStartSizeVar(0)
|
|
|
|
emitter:setEndSpin(0)
|
|
|
|
emitter:setEndSpinVar(0)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(80.0)
|
|
|
|
emitter:setStartSizeVar(40.0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE )
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(true)
|
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleBigFlower")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoRotFlower
|
|
|
|
---------------------------------
|
|
|
|
local function DemoRotFlower()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(300)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
background:addChild(emitter, 10)
|
|
|
|
----emitter:release() -- win32 : Remove this line
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- duration
|
|
|
|
emitter:setDuration(-1)
|
|
|
|
|
|
|
|
-- gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setGravity(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(90)
|
|
|
|
emitter:setAngleVar(360)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
emitter:setSpeed(160)
|
|
|
|
emitter:setSpeedVar(20)
|
|
|
|
|
|
|
|
-- radial
|
|
|
|
emitter:setRadialAccel(-120)
|
|
|
|
emitter:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- tagential
|
|
|
|
emitter:setTangentialAccel(30)
|
|
|
|
emitter:setTangentialAccelVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(160, 240)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(3)
|
|
|
|
emitter:setLifeVar(1)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
emitter:setStartSpin(0)
|
|
|
|
emitter:setStartSpinVar(0)
|
|
|
|
emitter:setEndSpin(0)
|
|
|
|
emitter:setEndSpinVar(2000)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(30.0)
|
|
|
|
emitter:setStartSizeVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE )
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(false)
|
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("ParticleRotFlower")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoModernArt
|
|
|
|
---------------------------------
|
|
|
|
local function DemoModernArt()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(1000)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
background:addChild(emitter, 10)
|
|
|
|
----emitter:release()
|
|
|
|
|
|
|
|
-- duration
|
|
|
|
emitter:setDuration(-1)
|
|
|
|
|
|
|
|
-- gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setGravity(cc.p(0,0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(0)
|
|
|
|
emitter:setAngleVar(360)
|
|
|
|
|
|
|
|
-- radial
|
|
|
|
emitter:setRadialAccel(70)
|
|
|
|
emitter:setRadialAccelVar(10)
|
|
|
|
|
|
|
|
-- tagential
|
|
|
|
emitter:setTangentialAccel(80)
|
|
|
|
emitter:setTangentialAccelVar(0)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
emitter:setSpeed(50)
|
|
|
|
emitter:setSpeedVar(10)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(s.width / 2, s.height / 2)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(2.0)
|
|
|
|
emitter:setLifeVar(0.3)
|
|
|
|
|
|
|
|
-- emits per frame
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(1.0)
|
|
|
|
emitter:setStartSizeVar(1.0)
|
|
|
|
emitter:setEndSize(32.0)
|
|
|
|
emitter:setEndSizeVar(8.0)
|
|
|
|
|
|
|
|
-- texture
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(false)
|
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("Varying size")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoRing
|
|
|
|
---------------------------------
|
|
|
|
local function DemoRing()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleFlower:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
background:addChild(emitter, 10)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
|
2013-03-05 14:46:18 +08:00
|
|
|
emitter:setLifeVar(0)
|
|
|
|
emitter:setLife(10)
|
|
|
|
emitter:setSpeed(100)
|
|
|
|
emitter:setSpeedVar(0)
|
|
|
|
emitter:setEmissionRate(10000)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString("Ring Demo")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- ParallaxParticle
|
|
|
|
---------------------------------
|
|
|
|
local function ParallaxParticle()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
|
|
|
background:getParent():removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local p = cc.ParallaxNode:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(p, 5)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local p1 = cc.Sprite:create(s_back3)
|
|
|
|
local p2 = cc.Sprite:create(s_back3)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
p:addChild(p1, 1, cc.p(0.5, 1), cc.p(0, 250))
|
|
|
|
p:addChild(p2, 2, cc.p(1.5, 1), cc.p(0, 50))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleFlower:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- emitter:retain()
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-03-05 14:46:18 +08:00
|
|
|
p1:addChild(emitter, 10)
|
|
|
|
emitter:setPosition(250, 200)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local par = cc.ParticleSun:create()
|
2013-03-05 14:46:18 +08:00
|
|
|
p2:addChild(par, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
par:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local move = cc.MoveBy:create(4, cc.p(300,0))
|
2012-08-29 17:17:36 +08:00
|
|
|
local move_back = move:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create(move, move_back)
|
|
|
|
p:runAction(cc.RepeatForever:create(seq))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
titleLabel:setString("Parallax + Particles")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- DemoParticleFromFile
|
|
|
|
---------------------------------
|
|
|
|
local function DemoParticleFromFile(name)
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
|
|
|
local filename = "Particles/" .. name .. ".plist"
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:create(filename)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(emitter, 10)
|
|
|
|
|
|
|
|
setEmitterPosition()
|
|
|
|
|
|
|
|
titleLabel:setString(name)
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- RadiusMode1
|
|
|
|
---------------------------------
|
|
|
|
local function RadiusMode1()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(200)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(emitter, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/stars-grayscale.png"))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- duration
|
2013-11-30 01:09:38 +08:00
|
|
|
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEmitterMode(cc.PARTICLE_MODE_RADIUS)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode: start and end radius in pixels
|
|
|
|
emitter:setStartRadius(0)
|
|
|
|
emitter:setStartRadiusVar(0)
|
|
|
|
emitter:setEndRadius(160)
|
|
|
|
emitter:setEndRadiusVar(0)
|
|
|
|
|
|
|
|
-- radius mode: degrees per second
|
|
|
|
emitter:setRotatePerSecond(180)
|
|
|
|
emitter:setRotatePerSecondVar(0)
|
|
|
|
|
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(90)
|
|
|
|
emitter:setAngleVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(s.width / 2, s.height / 2)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(5)
|
|
|
|
emitter:setLifeVar(0)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
emitter:setStartSpin(0)
|
|
|
|
emitter:setStartSpinVar(0)
|
|
|
|
emitter:setEndSpin(0)
|
|
|
|
emitter:setEndSpinVar(0)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(32)
|
|
|
|
emitter:setStartSizeVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE )
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(false)
|
|
|
|
|
|
|
|
titleLabel:setString("Radius Mode: Spiral")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- RadiusMode2
|
|
|
|
---------------------------------
|
|
|
|
local function RadiusMode2()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(200)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(emitter, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/stars-grayscale.png"))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- duration
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY )
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEmitterMode(cc.PARTICLE_MODE_RADIUS)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode: start and end radius in pixels
|
|
|
|
emitter:setStartRadius(100)
|
|
|
|
emitter:setStartRadiusVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndRadius(cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS)
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter:setEndRadiusVar(0)
|
|
|
|
|
|
|
|
-- radius mode: degrees per second
|
|
|
|
emitter:setRotatePerSecond(45)
|
|
|
|
emitter:setRotatePerSecondVar(0)
|
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(90)
|
|
|
|
emitter:setAngleVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(s.width / 2, s.height / 2)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(4)
|
|
|
|
emitter:setLifeVar(0)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
emitter:setStartSpin(0)
|
|
|
|
emitter:setStartSpinVar(0)
|
|
|
|
emitter:setEndSpin(0)
|
|
|
|
emitter:setEndSpinVar(0)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(32)
|
|
|
|
emitter:setStartSizeVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(false)
|
|
|
|
|
|
|
|
titleLabel:setString("Radius Mode: Semi Circle")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- Issue704
|
|
|
|
---------------------------------
|
|
|
|
local function Issue704()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:createWithTotalParticles(100)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(emitter, 10)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- duration
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEmitterMode(cc.PARTICLE_MODE_RADIUS)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode: start and end radius in pixels
|
|
|
|
emitter:setStartRadius(50)
|
|
|
|
emitter:setStartRadiusVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndRadius(cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS )
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter:setEndRadiusVar(0)
|
|
|
|
|
|
|
|
-- radius mode: degrees per second
|
|
|
|
emitter:setRotatePerSecond(0)
|
|
|
|
emitter:setRotatePerSecondVar(0)
|
|
|
|
|
|
|
|
|
|
|
|
-- angle
|
|
|
|
emitter:setAngle(90)
|
|
|
|
emitter:setAngleVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
|
|
|
emitter:setPosition(s.width / 2, s.height / 2)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
emitter:setLife(5)
|
|
|
|
emitter:setLifeVar(0)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
emitter:setStartSpin(0)
|
|
|
|
emitter:setStartSpinVar(0)
|
|
|
|
emitter:setEndSpin(0)
|
|
|
|
emitter:setEndSpinVar(0)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
|
|
|
emitter:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
emitter:setStartSize(16)
|
|
|
|
emitter:setStartSizeVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
emitter:setBlendAdditive(false)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local rot = cc.RotateBy:create(16, 360)
|
|
|
|
emitter:runAction(cc.RepeatForever:create(rot))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
titleLabel:setString("Issue 704. Free + Rot")
|
|
|
|
subtitleLabel:setString("Emitted particles should not rotate")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- Issue870
|
|
|
|
---------------------------------
|
|
|
|
local Issue870_index = nil
|
|
|
|
local Issue870_entry = nil
|
|
|
|
|
|
|
|
local function updateQuads(dt)
|
2012-08-30 16:38:16 +08:00
|
|
|
update(dt)
|
|
|
|
|
2012-08-29 17:17:36 +08:00
|
|
|
Issue870_index = math.mod(Issue870_index + 1, 4)
|
2013-08-20 13:44:37 +08:00
|
|
|
local rect = cc.rect(Issue870_index * 32, 0, 32, 32)
|
2012-08-29 17:17:36 +08:00
|
|
|
emitter:setTextureWithRect(emitter:getTexture(), rect)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function Issue870_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-29 17:17:36 +08:00
|
|
|
Issue870_entry = scheduler:scheduleScriptFunc(updateQuads, 2.0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-29 17:17:36 +08:00
|
|
|
scheduler:unscheduleScriptEntry(Issue870_entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function Issue870()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local system = cc.ParticleSystemQuad:create("Particles/SpinningPeas.plist")
|
|
|
|
system:setTextureWithRect(cc.TextureCache:getInstance():addImage("Images/particles.png"), cc.rect(0,0,32,32))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(system, 10)
|
|
|
|
emitter = system
|
|
|
|
|
|
|
|
Issue870_index = 0
|
|
|
|
layer:registerScriptHandler(Issue870_onEnterOrExit)
|
|
|
|
|
|
|
|
titleLabel:setString("Issue 870. SubRect")
|
|
|
|
subtitleLabel:setString("Every 2 seconds the particle should change")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- MultipleParticleSystems
|
|
|
|
---------------------------------
|
|
|
|
local function MultipleParticleSystems()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.TextureCache:getInstance():addImage("Images/particles.png")
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
for i = 0, 4 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local particleSystem = cc.ParticleSystemQuad:create("Particles/SpinningPeas.plist")
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setPosition(i * 50, i * 50)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setPositionType(cc.POSITION_TYPE_GROUPED )
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(particleSystem)
|
|
|
|
end
|
|
|
|
|
|
|
|
emitter = nil
|
|
|
|
|
|
|
|
titleLabel:setString("Multiple particle systems")
|
|
|
|
subtitleLabel:setString("v1.1 test: FPS should be lower than next test")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- MultipleParticleSystemsBatched
|
|
|
|
---------------------------------
|
|
|
|
local function MultipleParticleSystemsBatched()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local batchNode = cc.ParticleBatchNode:createWithTexture(nil, 3000)
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(batchNode, 1, 2)
|
|
|
|
|
|
|
|
for i = 0, 4 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local particleSystem = cc.ParticleSystemQuad:create("Particles/SpinningPeas.plist")
|
|
|
|
particleSystem:setPositionType(cc.POSITION_TYPE_GROUPED )
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setPosition(i * 50, i * 50)
|
|
|
|
batchNode:setTexture(particleSystem:getTexture())
|
|
|
|
batchNode:addChild(particleSystem)
|
|
|
|
end
|
|
|
|
|
|
|
|
emitter = nil
|
|
|
|
|
|
|
|
titleLabel:setString("Multiple particle systems batched")
|
|
|
|
subtitleLabel:setString("v1.1 test: should perform better than previous test")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- AddAndDeleteParticleSystems
|
|
|
|
---------------------------------
|
|
|
|
local AddAndDeleteParticleSystems_entry = nil
|
|
|
|
local AddAndDeleteParticleSystems_batchNode = nil
|
|
|
|
|
|
|
|
local function removeSystem(dt)
|
2012-08-30 16:38:16 +08:00
|
|
|
update(dt)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local ChildrenCount = table.getn(AddAndDeleteParticleSystems_batchNode:getChildren())
|
2012-08-29 17:17:36 +08:00
|
|
|
if ChildrenCount > 0 then
|
|
|
|
cclog("remove random system")
|
|
|
|
local rand = math.mod(math.random(1, 999999), ChildrenCount - 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
AddAndDeleteParticleSystems_batchNode:removeChild(AddAndDeleteParticleSystems_batchNode:getChildren()[(rand)], true)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
--add new
|
2013-08-20 13:44:37 +08:00
|
|
|
local particleSystem = cc.ParticleSystemQuad:create("Particles/Spiral.plist")
|
|
|
|
particleSystem:setPositionType(cc.POSITION_TYPE_GROUPED )
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setTotalParticles(200)
|
|
|
|
|
|
|
|
particleSystem:setPosition(math.mod(math.random(1, 999999), 300) ,math.mod(math.random(1, 999999), 400))
|
|
|
|
|
|
|
|
cclog("add a new system")
|
|
|
|
local randZ = math.floor(math.random() * 100)
|
|
|
|
AddAndDeleteParticleSystems_batchNode:addChild(particleSystem, randZ, -1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function AddAndDeleteParticleSystems_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-29 17:17:36 +08:00
|
|
|
AddAndDeleteParticleSystems_entry = scheduler:scheduleScriptFunc(removeSystem, 2.0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-29 17:17:36 +08:00
|
|
|
scheduler:unscheduleScriptEntry(AddAndDeleteParticleSystems_entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function AddAndDeleteParticleSystems()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
|
|
|
--adds the texture inside the plist to the texture cache
|
2013-08-20 13:44:37 +08:00
|
|
|
AddAndDeleteParticleSystems_batchNode = cc.ParticleBatchNode:createWithTexture(nil, 16000)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
layer:addChild(AddAndDeleteParticleSystems_batchNode, 1, 2)
|
|
|
|
|
|
|
|
for i = 0, 5 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local particleSystem = cc.ParticleSystemQuad:create("Particles/Spiral.plist")
|
2012-08-29 17:17:36 +08:00
|
|
|
AddAndDeleteParticleSystems_batchNode:setTexture(particleSystem:getTexture())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setPositionType(cc.POSITION_TYPE_GROUPED )
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setTotalParticles(200)
|
|
|
|
|
|
|
|
particleSystem:setPosition(i * 15 + 100, i * 15 + 100)
|
|
|
|
|
|
|
|
local randZ = math.floor(math.random() * 100)
|
|
|
|
AddAndDeleteParticleSystems_batchNode:addChild(particleSystem, randZ, -1)
|
|
|
|
end
|
|
|
|
|
|
|
|
layer:registerScriptHandler(AddAndDeleteParticleSystems_onEnterOrExit)
|
|
|
|
emitter = nil
|
|
|
|
|
|
|
|
titleLabel:setString("Add and remove Particle System")
|
|
|
|
subtitleLabel:setString("v1.1 test: every 2 sec 1 system disappear, 1 appears")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- ReorderParticleSystems *
|
|
|
|
-- problem
|
|
|
|
---------------------------------
|
|
|
|
local ReorderParticleSystems_entry = nil
|
|
|
|
local ReorderParticleSystems_batchNode = nil
|
|
|
|
|
|
|
|
local function reorderSystem(dt)
|
2012-08-30 16:38:16 +08:00
|
|
|
update(dt)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local childArray = ReorderParticleSystems_batchNode:getChildren()
|
|
|
|
local random = math.random(1,table.getn(childArray))
|
|
|
|
local child = childArray[random]
|
|
|
|
-- problem: there's no getZOrder() for cc.Object
|
2012-08-30 16:38:16 +08:00
|
|
|
-- ReorderParticleSystems_batchNode:reorderChild(child, child:getZOrder() - 1)
|
2012-08-29 17:17:36 +08:00
|
|
|
ReorderParticleSystems_batchNode:reorderChild(child, math.random(0, 99999))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ReorderParticleSystems_onEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-03-05 14:46:18 +08:00
|
|
|
if tag == "enter" then
|
2012-08-29 17:17:36 +08:00
|
|
|
ReorderParticleSystems_entry = scheduler:scheduleScriptFunc(reorderSystem, 2.0, false)
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif tag == "exit" then
|
2012-08-29 17:17:36 +08:00
|
|
|
scheduler:unscheduleScriptEntry(ReorderParticleSystems_entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ReorderParticleSystems()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background ,true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
ReorderParticleSystems_batchNode = cc.ParticleBatchNode:create("Images/stars-grayscale.png", 3000)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
layer:addChild(ReorderParticleSystems_batchNode, 1, 2)
|
|
|
|
|
|
|
|
for i = 0, 2 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local particleSystem = cc.ParticleSystemQuad:createWithTotalParticles(200)
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setTexture(ReorderParticleSystems_batchNode:getTexture())
|
|
|
|
|
|
|
|
-- duration
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setDuration(cc.PARTICLE_DURATION_INFINITY)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setEmitterMode(cc.PARTICLE_MODE_RADIUS)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- radius mode: 100 pixels from center
|
|
|
|
particleSystem:setStartRadius(100)
|
|
|
|
particleSystem:setStartRadiusVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setEndRadius(cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS )
|
2012-08-29 17:17:36 +08:00
|
|
|
particleSystem:setEndRadiusVar(0) -- not used when start == end
|
|
|
|
|
|
|
|
-- radius mode: degrees per second
|
|
|
|
-- 45 * 4 seconds of life = 180 degrees
|
|
|
|
particleSystem:setRotatePerSecond(45)
|
|
|
|
particleSystem:setRotatePerSecondVar(0)
|
|
|
|
|
|
|
|
|
|
|
|
-- angle
|
|
|
|
particleSystem:setAngle(90)
|
|
|
|
particleSystem:setAngleVar(0)
|
|
|
|
|
|
|
|
-- emitter position
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setPosVar(cc.p(0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
particleSystem:setLife(4)
|
|
|
|
particleSystem:setLifeVar(0)
|
|
|
|
|
|
|
|
-- spin of particles
|
|
|
|
particleSystem:setStartSpin(0)
|
|
|
|
particleSystem:setStartSpinVar(0)
|
|
|
|
particleSystem:setEndSpin(0)
|
|
|
|
particleSystem:setEndSpinVar(0)
|
|
|
|
|
|
|
|
-- color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
local startColor = cc.c4f(0, 0, 0, 1)
|
2012-08-29 17:17:36 +08:00
|
|
|
if i == 0 then startColor.r = 1
|
|
|
|
elseif i == 1 then startColor.g = 1
|
|
|
|
elseif i == 2 then startColor.b = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
particleSystem:setStartColor(startColor)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setStartColorVar(cc.c4f(0, 0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
local endColor = startColor
|
|
|
|
particleSystem:setEndColor(endColor)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setEndColorVar(cc.c4f(0, 0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- size, in pixels
|
|
|
|
particleSystem:setStartSize(32)
|
|
|
|
particleSystem:setStartSizeVar(0)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setEndSize(cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
-- emits per second
|
|
|
|
particleSystem:setEmissionRate(particleSystem:getTotalParticles() / particleSystem:getLife())
|
|
|
|
|
|
|
|
-- additive
|
|
|
|
particleSystem:setPosition(i * 10 + 120, 200)
|
|
|
|
|
|
|
|
ReorderParticleSystems_batchNode:addChild(particleSystem)
|
2013-08-20 13:44:37 +08:00
|
|
|
particleSystem:setPositionType(cc.POSITION_TYPE_FREE )
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
--particleSystem:release()
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
layer:registerScriptHandler(ReorderParticleSystems_onEnterOrExit)
|
|
|
|
emitter = nil
|
|
|
|
|
|
|
|
titleLabel:setString("reorder systems")
|
|
|
|
subtitleLabel:setString("changes every 2 seconds")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- PremultipliedAlphaTest
|
|
|
|
---------------------------------
|
|
|
|
local function PremultipliedAlphaTest()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 255))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:create("Particles/BoilingFoam.plist")
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setBlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
--assert(emitter:getOpacityModifyRGB(), "Particle texture does not have premultiplied alpha, test is useless")
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter:setStartColor(cc.c4f(1, 1, 1, 1))
|
|
|
|
emitter:setEndColor(cc.c4f(1, 1, 1, 0))
|
|
|
|
emitter:setStartColorVar(cc.c4f(0, 0, 0, 0))
|
|
|
|
emitter:setEndColorVar(cc.c4f(0, 0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
|
|
|
|
layer:addChild(emitter, 10)
|
|
|
|
|
|
|
|
titleLabel:setString("premultiplied alpha")
|
|
|
|
subtitleLabel:setString("no black halo, particles should fade out")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- PremultipliedAlphaTest2
|
|
|
|
---------------------------------
|
|
|
|
local function PremultipliedAlphaTest2()
|
|
|
|
local layer = getBaseLayer()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
layer:setColor(cc.c3b(0, 0, 0))
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:removeChild(background, true)
|
|
|
|
background = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
emitter = cc.ParticleSystemQuad:create("Particles/TestPremultipliedAlpha.plist")
|
2012-08-29 17:17:36 +08:00
|
|
|
layer:addChild(emitter ,10)
|
|
|
|
|
|
|
|
titleLabel:setString("premultiplied alpha 2")
|
|
|
|
subtitleLabel:setString("Arrows should be faded")
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- Particle Test
|
|
|
|
---------------------------------
|
2012-08-30 15:32:29 +08:00
|
|
|
function CreateParticleLayer()
|
|
|
|
if SceneIdx == 0 then return ParticleReorder()
|
|
|
|
elseif SceneIdx == 1 then return ParticleBatchHybrid()
|
|
|
|
elseif SceneIdx == 2 then return ParticleBatchMultipleEmitters()
|
|
|
|
elseif SceneIdx == 3 then return DemoFlower()
|
|
|
|
elseif SceneIdx == 4 then return DemoGalaxy()
|
|
|
|
elseif SceneIdx == 5 then return DemoFirework()
|
|
|
|
elseif SceneIdx == 6 then return DemoSpiral()
|
|
|
|
elseif SceneIdx == 7 then return DemoSun()
|
|
|
|
elseif SceneIdx == 8 then return DemoMeteor()
|
|
|
|
elseif SceneIdx == 9 then return DemoFire()
|
|
|
|
elseif SceneIdx == 10 then return DemoSmoke()
|
|
|
|
elseif SceneIdx == 11 then return DemoExplosion()
|
|
|
|
elseif SceneIdx == 12 then return DemoSnow()
|
|
|
|
elseif SceneIdx == 13 then return DemoRain()
|
|
|
|
elseif SceneIdx == 14 then return DemoBigFlower()
|
|
|
|
elseif SceneIdx == 15 then return DemoRotFlower()
|
|
|
|
elseif SceneIdx == 16 then return DemoModernArt()
|
|
|
|
elseif SceneIdx == 17 then return DemoRing()
|
|
|
|
elseif SceneIdx == 18 then return ParallaxParticle()
|
|
|
|
elseif SceneIdx == 19 then return DemoParticleFromFile("BoilingFoam")
|
|
|
|
elseif SceneIdx == 20 then return DemoParticleFromFile("BurstPipe")
|
|
|
|
elseif SceneIdx == 21 then return DemoParticleFromFile("Comet")
|
|
|
|
elseif SceneIdx == 22 then return DemoParticleFromFile("debian")
|
|
|
|
elseif SceneIdx == 23 then return DemoParticleFromFile("ExplodingRing")
|
|
|
|
elseif SceneIdx == 24 then return DemoParticleFromFile("LavaFlow")
|
|
|
|
elseif SceneIdx == 25 then return DemoParticleFromFile("SpinningPeas")
|
|
|
|
elseif SceneIdx == 26 then return DemoParticleFromFile("SpookyPeas")
|
|
|
|
elseif SceneIdx == 27 then return DemoParticleFromFile("Upsidedown")
|
|
|
|
elseif SceneIdx == 28 then return DemoParticleFromFile("Flower")
|
|
|
|
elseif SceneIdx == 29 then return DemoParticleFromFile("Spiral")
|
|
|
|
elseif SceneIdx == 30 then return DemoParticleFromFile("Galaxy")
|
|
|
|
elseif SceneIdx == 31 then return DemoParticleFromFile("Phoenix")
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif SceneIdx == 32 then return DemoParticleFromFile("lines")
|
|
|
|
elseif SceneIdx == 33 then return RadiusMode1()
|
|
|
|
elseif SceneIdx == 34 then return RadiusMode2()
|
|
|
|
elseif SceneIdx == 35 then return Issue704()
|
|
|
|
elseif SceneIdx == 36 then return Issue870()
|
2012-08-30 15:32:29 +08:00
|
|
|
--elseif SceneIdx == 36 then return Issue1201()
|
2012-08-29 17:17:36 +08:00
|
|
|
-- v1.1 tests
|
2013-03-05 14:46:18 +08:00
|
|
|
elseif SceneIdx == 37 then return MultipleParticleSystems()
|
|
|
|
elseif SceneIdx == 38 then return MultipleParticleSystemsBatched()
|
|
|
|
elseif SceneIdx == 39 then return AddAndDeleteParticleSystems()
|
|
|
|
elseif SceneIdx == 40 then return ReorderParticleSystems()
|
|
|
|
elseif SceneIdx == 41 then return PremultipliedAlphaTest()
|
|
|
|
elseif SceneIdx == 42 then return PremultipliedAlphaTest2()
|
2012-08-29 17:17:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParticleTest()
|
2012-08-30 15:32:29 +08:00
|
|
|
cclog("ParticleTest")
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2012-08-29 17:17:36 +08:00
|
|
|
|
2012-08-30 15:32:29 +08:00
|
|
|
SceneIdx = -1
|
|
|
|
scene:addChild(nextAction())
|
2012-08-29 17:17:36 +08:00
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
|
|
|
return scene
|
|
|
|
end
|