cocos2d_x+lua ------触屏事件
CCLayer要实现触屏的话、只需要两步就可以完成
[cpp]
--重写相应的触摸函数
ptTouchBegan = nil
ptTouchEnd = nil
local function onTouchBegan(x, y)
ptTouchBegan = CCPointMake(x,y)
end
www.zzzyk.com
local function onTouchMoved(x, y)
end
local function onTouchEnded(x, y)
ptTouchEnd = CCPointMake(x,y)
ptTouchBegan = nil
ptTouchEnd = nil
end
local function onTouch(eventType, x, y)
if eventType == CCTOUCHBEGAN then
return onTouchBegan(x, y)
elseif eventType == CCTOUCHMOVED then
return onTouchMoved(x, y)
else
return onTouchEnded(x, y)
end
end
--注册触摸函数
layer:registerScriptTouchHandler(onTouch)
--设置成可触摸
layer:setIsTouchEnabled(true)
CCScene要实现触屏的话、省掉注册触摸函数就可以了
补充:移动开发 , 其他 ,