How to use CCCallFunc in Lua?
cocos2d-1.0.1-x-0.11.0:
function CALLBACK_LUAFUNC()
cocos2d.CCLog(‘call back lua func’)
end
local action1 = cocos2d.CCRotateTo:actionWithDuration( 1, 180);
local action2 = cocos2d.CCCallFuncND:actionWithScriptFuncName(“CALLBACK_LUAFUNC”)
mAction:runAction(cocos2d.CCSequence:actionOneTwo(action1, action2))
cocos2d-1.0.1-x-0.12.0 release:
???
forget CCCallFunc, try NEW Lua Framework for cocos2d-x
download: https://github.com/dualface/qeeplay-lua-cocos2d-x
require("transition")
local function CALLBACK_LUAFUNC()
print('call back lua func')
end
local action1 = CCRotateTo:actionWithDuration(1, 180);
transition.to(myNode, action1, {
onComplete = CALLBACK_LUAFUNC
})
YuLei Liao wrote:
forget CCCallFunc, try NEW Lua Framework for cocos2d-x
>
download: https://github.com/dualface/qeeplay-lua-cocos2d-x
>
but,
json.lua:3: module ‘cjson’ not found:
you can compile cjson (http://www.kyne.com.au/~mark/software/lua-cjson.php), or comment out require(“qeeplay.json”) in init.lua.
maybe ……
function performWithDelay(time, listener)
local handle
handle = scheduler:scheduleScriptFunc(function(e, v)
scheduler:unscheduleScriptEntry(handle)
listener(e, v)
end, time, false)
return handle
end
function to(target, action, args)
local delay = args.delay or 0
local time = args.time or 0.2
local onComplete = args.onComplete or onComplete
local entryid = nil
if args.easing then
if type(args.easing) “table” then
action = newEasing(action, unpack(args.easing))
else
action = newEasing(action, args.easing)
end
end
if type(time) \~= "number" then time = 0.2 end
if type(delay) “number” and delay \> 0 then
action:retain()
entryid = scheduler.performWithDelay(delay, function()
target:runAction(action)
action:release()
end)
else
target:runAction(action)
end
if type(onComplete) == “function” then
entryid = scheduler.performWithDelay(delay + time, onComplete)
end
return action, entryid
end