kao,搜了一圈,都是几百年前写的狗时,一篇完整的代码都没有,只好写一篇来水一水。
local someTest = class("someTest")
local scheduler = cc.Director:getInstance():getScheduler()
function someTest.showUI(layer)
someTest.gameLayer = layer
someTest:initLayer()
end
function someTest:initLayer()
local sp = cc.Sprite:create("gameOver.jpg");
sp:addTo(self.gameLayer)
sp:center()
sp:setName("lsplsp")
--sp:setTouchEnabled(true) 有些ui要设置开启触摸
local touchListen = cc.EventListenerTouchOneByOne:create() --创建触摸监听事件
touchListen:setSwallowTouches(true) --阻止穿透
touchListen:registerScriptHandler(function(touch, event)
local rect = sp:getBoundingBox()
log(touch:getLocation())
local point = touch:getLocation()
if cc.rectContainsPoint(rect, point ) then
log("开始触摸")
return true
end
log("no")
return false
end, cc.Handler.EVENT_TOUCH
cocos2dx实现节点拖动与触摸交互

本文介绍了在cocos2dx中为node、sprite和layer添加拖动及触摸响应效果的过程,由于现有资料过时,作者决定分享一篇详细教程。
最低0.47元/天 解锁文章
3659

被折叠的 条评论
为什么被折叠?



