【已解决】listView 触摸监听

使用cocostdio的listview的时候遇到一个问题,想要从listview中拖拽一个卡牌,将其中的图片拉到界面上。
这个时候需要判断在listview中item上的y坐标的移动距离,超过一定值,才发生移动。
请问我怎么获取listview里面item的坐标?

//listview 监听方法
listViewItemCallback(cocos2d::CCObject *pSender, TouchEventType type)
这个监听方法只能获取Type

你是想获取触摸点的位置么?目前cocostudio的触摸点均记录在控件的属性里的,可以参考下面的方法获取:

const CCPoint& getTouchStartPos();

const CCPoint& getTouchMovePos();

const CCPoint& getTouchEndPos();

谢谢,我试试

有没有这三个函数的使用示例啊……
感觉如果没在正确的地方使用的话,结果会很糟糕 :9:

正好跟你的需求一样,昨天刚写了个
分享给你吧 lua的

还没上真机调试过使用感受

估计还要微调下判断参数
自己试试吧

-----------------------------------------------------------------------羞射的分割线-----------------------------------------------------------------------

local movePoint = nil --移动中的坐标
local yuandianX = nil
local yuandianY = nil
local maxMove = 50 --水平移动最大判断距离
local touchPointX = nil --触摸点x
local touchPointY = nil --触摸点y
local moveState = 0 – 0:检测中 1:水平拖动 2:向上拖拽

– 列表点击事件
@param e event事件对象
@param etype event事件类型
function onCellClick(sender, eType)
local widget = tolua.cast(sender, “Widget”)
if eType == EventHelper.began then
moveState = 0
–记录点击的坐标 为了给下面移动时加上差值
touchPointX = widget:getTouchStartPos().x
touchPointY = widget:getTouchStartPos().y
widget:setBackGroundImage("")
elseif eType == EventHelper.move then
if moveState == 0 then
local currPoint = widget:getTouchMovePos()
–水平方向移动距离
local diffX = math.abs(currPoint.x - touchPointX)
– 向上拖动距离大于水平移动距离 判断为 拖拽卡牌
if math.abs(currPoint.y - touchPointY) > 30 then
local worldPoint = widget:convertToWorldSpace(CCPoint(0,0))
– TODO 刷新list
widget:removeFromParentAndCleanup(false)
_gLayer:addWidget(widget)
local newPoint = _gLayer:convertToNodeSpace(worldPoint)
widget:setPosition(newPoint)
movePoint = widget:getTouchStartPos()
– 记录触摸点与item原点的坐标差 下面在移动的时候要加上这个差 才能使item在点击的地方被拿起
yuandianX = widget:getPositionX() - movePoint.x
yuandianY = widget:getPositionY() - movePoint.y
moveState = 2
elseif diffX > maxMove then --水平移动距离超过限制判断为list拖动
moveState = 1
end
elseif moveState == 2 then
movePoint = widget:getTouchMovePos()
local toPoint = ccpAdd(CCPoint(yuandianX, yuandianY), movePoint)
widget:setPosition(toPoint)
end
end
end

先收藏,正要用到!

先要收藏 正要用到

太好了,先收藏。:8: