util.lua
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local scheduler = cc.Director:getInstance():getScheduler();
function dprint( ... )
if DEBUG then
print(...)
end
end
--打印带时间的日志
function trace(...)
print(os.date("%Y-%m-%d %H:%M:%S")..":", ...)
end
function delayCall(delay,callback)
local id
local function oncall()
scheduler:unscheduleScriptEntry(id);
callback();
end
id = scheduler:scheduleScriptFunc(oncall, delay,false);
return id;
end
function removeDelay(id)
scheduler:unscheduleScriptEntry(id);
end
function registerScriptTouchEvent(node,onTouchBegan,onTouchMoved,onTouchEnded)
-- local listener = cc.EventListenerTouchOneByOne:create()
-- listener:registerScriptHandler(touchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
-- listener:registerScriptHandler(touchMoved,cc.Handler.EVENT_TOUCH_MOVED )
-- listener:registerScriptHandler(touchEnded,cc.Handler.EVENT_TOUCH_ENDED )
-- --listener:setSwallowTouches(true) --不向下传递
-- local eventDispatcher = node:getEventDispatcher()
-- eventDispatcher:addEventListenerWithSceneGraphPriority(listener,node)
local touchListener = cc.EventListenerTouchOneByOne:create()
touchListener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
touchListener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED)
touchListener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED)
local eveDispatch = node:getEventDispatcher()
eveDispatch:addEventListenerWithSceneGraphPriority(touchListener, node)
end