Node之tags

local Test4_layer = nil
local Test4_delay2Entry = nil
local Test4_delay4Entry = nil

local function delay2(dt)//dt爲時間間隔
print(dt)
node = Test4_layer:getChildByTag(2)
local action1 = cc.RotateBy:create(3, 180) //此處當動作沒有做完時又重新執行爲什麼不從頭來,而是動作很連貫?答:如果要動作從頭播需要重新設置角度:node:setRotation(0)
node:runAction(action1)
end

local function delay4(dt)
scheduler:unscheduleScriptEntry(Test4_delay4Entry)
Test4_layer:removeChildByTag(3, false)
end

local function Test4_onEnterOrExit(tag)
if tag == “enter” then
Test4_delay2Entry = scheduler:scheduleScriptFunc(delay2, 2.0, false)
Test4_delay4Entry = scheduler:scheduleScriptFunc(delay4, 4.0, false)
elseif tag == “exit” then
scheduler:unscheduleScriptEntry(Test4_delay2Entry)
scheduler:unscheduleScriptEntry(Test4_delay4Entry)
end
end

local function Test4()
Test4_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))

Test4_layer:addChild(sp1, 0, 2)
Test4_layer:addChild(sp2, 0, 3)

Test4_layer:registerScriptHandler(Test4_onEnterOrExit)

Helper.titleLabel:setString("tags")
return Test4_layer

end

發佈了31 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章