Hi,
I’m trying to create somesort of scrolling list with images.
I create an rectangle, put it in the scrollGroup, add couple of images, add them to the scrollGroup.
Add touch event listeners to each image, and last but not least, add a touch event listener to the group, so i can scroll it up and down.
Dragging the whole group up and down works perfectly, but Corona doesn’t seem to detect the touch listeners for each image.
So problem is, the startDrag event is fired so the Group can be scrolled/moved together with all its images, but the touch listeners of the images don’t work anymore.
Any solution how to solve this?
ListGroup = display.newGroup()
shadeRect = display.newRect( 0, 140, 1024, 535 )
shadeRect:setFillColor( 0, 0, 0, 255 )
shadeRect.alpha = 0.3
ListGroup:insert(shadeRect)
function ImageClicked(event)
if (event.phase == "ended") then
-- Do something
end
end
Image1 = display.newImage("Number1.png", 0,0 )
Image1:addEventListener("touch", ImageClicked )
ListGroup:insert(Image1)
Image2 = display.newImage("Number2.png", 0,0 )
Image2:addEventListener("touch", ImageClicked )
ListGroup:insert(Image2)
local function startDrag( event )
local t = event.target
local phase = event.phase
if "began" == phase then
Dragging = false
display.getCurrentStage():setFocus( t )
t.isFocus = true
-- Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if "moved" == phase then
Dragging = true
t.x = event.x - t.x0
t.y = event.y - t.y0
if t.x \> 0 or t.x \< 0 then
t.x = 0
end
if t.x \< -1024 then
t.x = -1024
end
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
-- Stop further propagation of touch event!
return true
end
ListGroup:addEventListener( "touch", startDrag )
[import]uid: 50459 topic_id: 26067 reply_id: 326067[/import]
[import]uid: 52491 topic_id: 26067 reply_id: 105562[/import]