multiple event listener at the same time problems

hi i’m trying to move a display group who contains a lot of display.newImage and to drag items who are in the

group on the scene

but if scroll the display group i can’t drag items , and if i drag items on the scene i can’t scroll the group,

if i do one i can’t do the other and i want to do both, need help plz

How big are the images, do they cover the entirety of the scrollView or are there large gaps between?

If there are large gaps, you can set focus on the touched object in event.phase == “began” to prevent the scrollView from responding to the touch event, remembering to set focus to nil on event.phase == “ended”. The user can then scroll the view by moving their finger on an area not containing an image.

[lua]

  display.getCurrentStage():setFocus( event. target )
 

[/lua]

If the images take up most of the scrollVIew, you could detect how long the user holds their finger on an object - after a certain amount of time set the focus on the object as above.

As for dragging objects around, I’ve been using the excellent DMC dragdrop library lately for this task.

https://github.com/dmccuskey/DMC-Corona-Library/tree/master/examples/dmc_dragdrop/DMC-dragdrop-basic

http://docs.davidmccuskey.com/display/docs/Quick+Guide±+dmc_dragdrop

there are large gaps between images 

local function onRectangleTouch(event)

      local t  = event.target

      if event.phase == “began” then

        if (event.target ~= nil) then

            clik = 1

        local parent = t.parent

        parent:insert(t)

        display.getCurrentStage():setFocus(t)

        t.isFocus = true

        t.markX = event.xStart    

        t.markY = event.yStart

        screenGroup:insert(t)

        end

      elseif event.phase == “moved” then

        if (clik ~= 0) then

            t.x = (event.x - event.xStart) + t.markX

            t.y = (event.y - event.yStart) + t.markY

        end

      elseif event.phase == “ended”  then

       display.getCurrentStage():setFocus(nil)

       t.isFocus = False

       clik = 0

      end

      return true

end

local function createimage()

    local group = display.newGroup( )

    local position = 0

    for i = 1, #elements do

        local image = display.newImageRect(elements[i].img, elements[i].dir or CONTENT_DIR, 100, 100)

        image.x = 125 + position

        image.y = 100

        position = position + 120

        image:addEventListener( “touch”, onRectangleTouch ) 

        group:insert(image) 

    end

    return group

end

groupdisplay:insert(createimage())

groupdisplay:addEventListener(“touch”, groupdisplay)   i don’t know how to do both i don’t have a scrollview widget it’s a group.display  

thank you for these links I’ll watch

it’s too complicated compared to what I want to do I’ll try another way

hey can it be possible to clone  a display object?

for example i have an display object

and when i click on it i  duplicate the display object so i can move his clone and the original stay at his position 

When you first create the object, you need to store information about it, such as the filename, directory used etc

i.e.

[lua]

local image = display.newImageRect(elements[i].img, elements[i].dir or CONTENT_DIR, 100, 100)

image.file = elements[i].img

image.dir = elements[i].dir

[/lua]

Then when you click on it:

[lua]

local t = event.target

local image = display.newImageRect(t.file, t.dir, t.width, t.height)

image.x, image.y = t.x, t.y

[/lua]

thanks it works but i can’t move the clone, 

in event.phase == “moved”

what should i do? i tried image.x, image.y = event.x,event.y but it doesn’t work

How big are the images, do they cover the entirety of the scrollView or are there large gaps between?

If there are large gaps, you can set focus on the touched object in event.phase == “began” to prevent the scrollView from responding to the touch event, remembering to set focus to nil on event.phase == “ended”. The user can then scroll the view by moving their finger on an area not containing an image.

[lua]

  display.getCurrentStage():setFocus( event. target )
 

[/lua]

If the images take up most of the scrollVIew, you could detect how long the user holds their finger on an object - after a certain amount of time set the focus on the object as above.

As for dragging objects around, I’ve been using the excellent DMC dragdrop library lately for this task.

https://github.com/dmccuskey/DMC-Corona-Library/tree/master/examples/dmc_dragdrop/DMC-dragdrop-basic

http://docs.davidmccuskey.com/display/docs/Quick+Guide±+dmc_dragdrop

there are large gaps between images 

local function onRectangleTouch(event)

      local t  = event.target

      if event.phase == “began” then

        if (event.target ~= nil) then

            clik = 1

        local parent = t.parent

        parent:insert(t)

        display.getCurrentStage():setFocus(t)

        t.isFocus = true

        t.markX = event.xStart    

        t.markY = event.yStart

        screenGroup:insert(t)

        end

      elseif event.phase == “moved” then

        if (clik ~= 0) then

            t.x = (event.x - event.xStart) + t.markX

            t.y = (event.y - event.yStart) + t.markY

        end

      elseif event.phase == “ended”  then

       display.getCurrentStage():setFocus(nil)

       t.isFocus = False

       clik = 0

      end

      return true

end

local function createimage()

    local group = display.newGroup( )

    local position = 0

    for i = 1, #elements do

        local image = display.newImageRect(elements[i].img, elements[i].dir or CONTENT_DIR, 100, 100)

        image.x = 125 + position

        image.y = 100

        position = position + 120

        image:addEventListener( “touch”, onRectangleTouch ) 

        group:insert(image) 

    end

    return group

end

groupdisplay:insert(createimage())

groupdisplay:addEventListener(“touch”, groupdisplay)   i don’t know how to do both i don’t have a scrollview widget it’s a group.display  

thank you for these links I’ll watch

it’s too complicated compared to what I want to do I’ll try another way

hey can it be possible to clone  a display object?

for example i have an display object

and when i click on it i  duplicate the display object so i can move his clone and the original stay at his position 

When you first create the object, you need to store information about it, such as the filename, directory used etc

i.e.

[lua]

local image = display.newImageRect(elements[i].img, elements[i].dir or CONTENT_DIR, 100, 100)

image.file = elements[i].img

image.dir = elements[i].dir

[/lua]

Then when you click on it:

[lua]

local t = event.target

local image = display.newImageRect(t.file, t.dir, t.width, t.height)

image.x, image.y = t.x, t.y

[/lua]

thanks it works but i can’t move the clone, 

in event.phase == “moved”

what should i do? i tried image.x, image.y = event.x,event.y but it doesn’t work