local Test5_entry = nil
local Test5_layer = nil
local function Test5_addAndRemove(dt)
local sp1 = Test5_layer:getChildByTag(kTagSprite1)
local sp2 = Test5_layer:getChildByTag(kTagSprite2)
sp1:retain()
sp2:retain()//此函数的作用是给引用计数加一,防止remove的时候释放sp2
Test5_layer:removeChild(sp1, false)
Test5_layer:removeChild(sp2, true)//清除标志为true会把sp2的动作停下
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2) //如果sp2:retain()注释掉的话,此时addChild的sp2是个空值
sp1:release()
sp2:release()
end
local function Test5_onEnterOrExit(tag)
if tag == "enter" then
Test5_entry = scheduler:scheduleScriptFunc(Test5_addAndRemove, 2.0, false)
elseif tag == "exit" then
scheduler:unscheduleScriptEntry(Test5_entry)
end
end
local function Test5()
Test5_layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp2 = cc.Sprite:create(s_pPathSister2)
sp1:setPosition(cc.p(100, 160))
sp2:setPosition(cc.p(380, 160))
local rot = cc.RotateBy:create(2, 360)
local rot_back = rot:reverse()
local forever = cc.RepeatForever:create(cc.Sequence:create(rot, rot_back))
local rot2 = cc.RotateBy:create(2, 360)
local rot2_back = rot2:reverse()
local forever2 = cc.RepeatForever:create(cc.Sequence:create(rot2, rot2_back))
forever:setTag(101)
forever2:setTag(102)//setTag的作用就是设置标签,标签可以是任意玩意
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2)
sp1:runAction(forever)
sp2:runAction(forever2)
Test5_layer:registerScriptHandler(Test5_onEnterOrExit)
Helper.titleLabel:setString("remove and cleanup")
return Test5_layer
end
local Test5_layer = nil
local function Test5_addAndRemove(dt)
local sp1 = Test5_layer:getChildByTag(kTagSprite1)
local sp2 = Test5_layer:getChildByTag(kTagSprite2)
sp1:retain()
sp2:retain()//此函数的作用是给引用计数加一,防止remove的时候释放sp2
Test5_layer:removeChild(sp1, false)
Test5_layer:removeChild(sp2, true)//清除标志为true会把sp2的动作停下
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2) //如果sp2:retain()注释掉的话,此时addChild的sp2是个空值
sp1:release()
sp2:release()
end
local function Test5_onEnterOrExit(tag)
if tag == "enter" then
Test5_entry = scheduler:scheduleScriptFunc(Test5_addAndRemove, 2.0, false)
elseif tag == "exit" then
scheduler:unscheduleScriptEntry(Test5_entry)
end
end
local function Test5()
Test5_layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp2 = cc.Sprite:create(s_pPathSister2)
sp1:setPosition(cc.p(100, 160))
sp2:setPosition(cc.p(380, 160))
local rot = cc.RotateBy:create(2, 360)
local rot_back = rot:reverse()
local forever = cc.RepeatForever:create(cc.Sequence:create(rot, rot_back))
local rot2 = cc.RotateBy:create(2, 360)
local rot2_back = rot2:reverse()
local forever2 = cc.RepeatForever:create(cc.Sequence:create(rot2, rot2_back))
forever:setTag(101)
forever2:setTag(102)//setTag的作用就是设置标签,标签可以是任意玩意
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2)
sp1:runAction(forever)
sp2:runAction(forever2)
Test5_layer:registerScriptHandler(Test5_onEnterOrExit)
Helper.titleLabel:setString("remove and cleanup")
return Test5_layer
end