【quick-x】学习笔记(基本代码段)

结束程序

CCDirector:sharedDirector():endToLua()

场景转换

CCDirector:sharedDirector():replaceScene(/scene/)

清除缓存

CCDirector:sharedDirector():purgeCachedData()
一般在新场景生成的时候调用,清除掉的缓存在再次使用的时候还是会加载进来

CCLayer touch事件监听

/cc_layer_obj/:setTouchEnabled(true) => 设置此layer监听touch
/cc_layer_obj/:registerScriptTouchHandler(/int function_point/) => 设置touch回调函数
/cc_layer_obj/:unregisterScriptTouchHandler(/int function_point/) => 移除回调监听
touch回调写法:
eventType => "began" or "moved" or "ended" or "cancelled"
local function on_touch(eventType, x, y)
end

CCLayer生命周期监听

继承CCLayer的类实现以下函数
function /class/:onEnter() end => 载入
function /class/:onEnterTransitionDidFinish() end => 使用CCTransitionScene在Transition完成时调用
function /class/:onExit() end => 退出
CCTransitionScene使用时的情况

CCLayer keypad事件监听

/cc_layer_obj/:setKeypadEnabled(true) => 设置此layer监听keypad
/cc_layer_obj/:registerScriptKeypadHandler(/int function_p/) => 设置keypad回调函数
/cc_layer_obj/.unregisterScriptKeypadHandler(/int function_p/) => 移除回调监听
keypad回调写法:
key => "backClicked" or "menuClicked"
local function on_keypad_pressed(key)
end

指定第一个运行的Lua文件

在AppDelegate.cpp中
CCString* pstrFileContent = CCString::createWithContentsOfFile(/xxx.lua/);

Lua开始程序

-- avaoid memory leak
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 500)

local scene = /xxx_scene/
CCDirector:sharedDirector:runWithScene(scene) => Enters the Director's main loop with the given Scene.
Call it to run only your FIRST scene. Don't call it if there is already a running scene.

CCMenuItem设置点击事件

/cc_menu_item/:registerScriptTapHandler(/call_back/) => 设置点击回调
回调函数写法
tag => 被点击的menuitem的tag
local function call_back(tag)
end

CCScheduler schedule

unsigned int scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused )
返回的int用于unscheduleScriptEntry的时候使用, fInterval调用周期, bPaused设置为false,不知何用
void unscheduleScriptEntry (unsigned int uScheduleScriptEntryID) => unschedule
demo:
local function call_back() print("scheduled") end
entry = CCDirector:getScheduler():scheduleScriptFunc(call_back, 2, false)
CCDirector:getScheduler():unscheduleScriptEntry(entry)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值