cocos2dx-lua?

Tags: 作者, word,

local addTimes = 0

local loadingLayer = nil

--[[

@desc處理touches事件

@parastring event

@return

--]]

local function onTouchesHandler( eventType, x, y )

if (eventType == "began") then

-- print("began")

if(loadingLayer and loadingLayer:isVisible()==true)then

return true

else

return false

end

elseif (eventType == "moved") then

else

-- print("end")

end

end

--[[

@desc回撥onEnter和onExit時間

@parastring event

@return void

--]]

local function onNodeEvent( event )

if (event == "enter") then

print("enter")

loadingLayer:registerScriptTouchHandler(onTouchesHandler, false, -99999, true)

loadingLayer:setTouchEnabled(true)

elseif (event == "exit") then

print("exit")

loadingLayer:unregisterScriptTouchHandler()

end

end

local function showLoading()

print("showLoading....")

loadingLayer = nil

loadingLayer = CCLayerColor:create(ccc4(0,0,0,155))

loadingLayer:registerScriptHandler(onNodeEvent)

local runningScene = CCDirector:sharedDirector():getRunningScene()

runningScene:addChild(loadingLayer,999999999)

--

local loadingSprite = CCSprite:create("load.png")

loadingSprite:setAnchorPoint(ccp(0.5, 0.5))

loadingSprite:setPosition(ccp(runningScene:getContentSize().width/2 , runningScene:getContentSize().height/2))

loadingSprite:setScale(g_fScaleX)

loadingLayer:addChild(loadingSprite)

-- 動畫

local loadEffectSprite = CCLayerSprite:layerSpriteWithName(CCString:create("load"), -1,CCString:create(""));

loadEffectSprite:retain()

loadEffectSprite:setAnchorPoint(ccp(0.5, 0.5))

loadEffectSprite:setPosition(ccp(loadingSprite:getContentSize().width*0.35, loadingSprite:getContentSize().height*0.1))

loadingSprite:addChild(loadEffectSprite)

loadEffectSprite:release()

end

function addLoadingUI()

addTimes = addTimes +1

if (addTimes==1) then

loadingLayer = tolua.cast(loadingLayer, "CCLayerColor")

if(loadingLayer == nil)then

showLoading()

end

loadingLayer:setVisible(true)

end

end

function reduceLoadingUI( )

addTimes = addTimes -1

if (addTimes<=0) then

loadingLayer = tolua.cast(loadingLayer, "CCLayerColor")

if (loadingLayer)then

loadingLayer:setVisible(false)

end

end

end

-- 直接停止

function stopLoadingUI( )

addTimes = 0

loadingLayer = tolua.cast(loadingLayer, "CCLayerColor")

if (loadingLayer)then

loadingLayer:setVisible(false)

end

end

相關問題答案