cocos进阶教程(5)回调函数和定时器的使用技巧

cc.CallFunc.create(selector, data)

selector:函数名(函数指针)

data:参数 table类型

函数写法

function(node,args )

node:动作调用对象,这个在系统会在-runAction的时候自动赋值进去的,不需要cc.CallFunc.create(selector, data)这里添加对象

args:这里是table格式的 参数表

function TestView:onCreate()
    local function func1(arg1, arg2)
        dump(arg1,"arg1")
        dump(arg2,"arg2")
    end

    local function func2(arg1, arg2)
        dump(arg1,"arg1")
        dump(arg2,"arg2")
    end

    local function func3(arg1, arg2)
        dump(arg1,"arg1")
        dump(arg2,"arg2")
    end

    local node = cc.Node:create()
    --这里必须要addChild(node),是生命周期跨越该函数 和 TestView同步 不然没法runAction 因为主对象没有
    self:addChild(node)
    dump(node,"node")
    local actions = {}
    local act1 = cc.CallFunc:create(func1, {"a","b","c"})
    local act2 = cc.CallFunc:create(func2, {"aa","bb","cc"})
    local act3 = cc.CallFunc:create(func3, {"aaa","bbb","ccc"})
    actions = {act2, act3, act1}

    local seq = cc.Sequence:create(actions)
    node:runAction(seq)
end

 Layer

layer:scheduleUpdateWithPriorityLua(update,0)

CameraZoomTest_layer:scheduleUpdateWithPriorityLua(CameraZoomTest_update, 0)

layer:unscheduleUpdate()

layer:registerScriptHandler(onNodeEvent)

Node

StressTest2_entry = scheduler:scheduleScriptFunc(shouldNotLeak, 6.0, false)

scheduler:unscheduleScriptEntry(StressTest2_entry)

原文地址:https://www.cnblogs.com/damowang/p/5009908.html