Single Swipe Across Multiple Display Objects? (Not Multitouch)

Hi,

I have several image objects displayed next two each other on the screen (Obj1, Obj2, Obj3) and I need to determine when the user swipes across all three objects in a single swipe, i.e. the touch begins on Obj1, moves across Obj 2, and ends on Obj 3 (or even ends “past” Obj 3). What is the best way to implement this? I’ve considered using a single EventListener for Obj 1 and then using display.getCurrentStage():setFocus( self ). Then I could use changes in the event.x coordinates to determine which objects the swipe went across and ended on. However, that seems like a pretty clunky implementation and I’d rather not have to separately hard code this for each of the 30 pages of my app that employs this type of swipe feature (since the objects on each page will have different x coordinates due to differing sizes).

Can anyone give any advice here? I’d greatly appreciate it.

Thanks! [import]uid: 76002 topic_id: 14226 reply_id: 314226[/import]

I hope this will get you started
[lua]local circle1 = display.newCircle(50, 50, 20)
circle1.tag =‘circle1’
local circle2 = display.newCircle(150, 50, 20)
circle2.tag =‘circle2’
local circle3 = display.newCircle(250, 50, 20)
circle3.tag =‘circle3’

function moveCircle( event )
print(event.target.tag)
end
circle1:addEventListener(“touch”, moveCircle)
circle2:addEventListener(“touch”, moveCircle)
circle3:addEventListener(“touch”, moveCircle)[/lua] [import]uid: 71210 topic_id: 14226 reply_id: 52429[/import]

Edit: I posted the below before I saw your response above. Thanks, I will look into using event.target.tag and will follow up if needed.

Just thinking a bit more…

Could I use event.target and assign local variables to the event.target of each phase of the swipe event, and then compare the targets for the “begin”, “moved”, and “ended” phases? Even if that worked, though, it still wouldn’t work correctly if the swipe started to the left of Obj 1, swiped across all three objects, and then ended past Obj3. [import]uid: 76002 topic_id: 14226 reply_id: 52432[/import]

so do you wan’t to start the swipe always at obj1 and ends at obj3 ?

Can you explain a bit more about the behavior you want to attain ? [import]uid: 71210 topic_id: 14226 reply_id: 52433[/import]

Sorry if I was unclear (and thanks again for your help here). Let me go into a bit more detail.

Generally, the swipe I want to handle will start on Obj1 and end at Obj3. If this swipe occurs, a particular audio file will be played, for example. However, my app is designed for young kids, so I expect that some of the swipes will not be this precise, i.e. a swipe might begin on Obj1, swipe across Obj2 and Obj3 and then end “past” Obj3. Ideally, I would like to be able to handle this behavior the same as if the swipe began on Obj1 and ended on Obj3.

Thanks again. [import]uid: 76002 topic_id: 14226 reply_id: 52434[/import]

hope this will help
[lua]local circle1 = display.newCircle(50, 50, 20)
circle1.tag =1
local circle2 = display.newCircle(150, 50, 20)
circle2.tag =2
local circle3 = display.newCircle(250, 50, 20)
circle3.tag =3

local objectSwiped = 0
function moveCircle( event )
if event.target.tag == objectSwiped + 1 then
objectSwiped = event.target.tag
print(objectSwiped)
if objectSwiped == 3 then
print(“all objects swiped”)
objectSwiped = 0
end
end
end
circle1:addEventListener(“touch”, moveCircle)
circle2:addEventListener(“touch”, moveCircle)
circle3:addEventListener(“touch”, moveCircle)[/lua] [import]uid: 71210 topic_id: 14226 reply_id: 52437[/import]

Thanks very much for your help! Got it working. [import]uid: 76002 topic_id: 14226 reply_id: 52544[/import]

is there a way to swap two image in the table…It is like I touch img1 and then I touch img4 then both img1 and img 4 gets interchanged…I have the image table along with the co-ordinates

[code]

local beta= {“alpha_1.png” , “alpha_2.png” , “alpha_3.png” , “alpha_4.png” ,
“alpha_5.png” , “alpha_6.png” , “alpha_7.png” , “alpha_8.png”}

local coordinates ={{x=092, y=470}, {x=197, y=470}, {x=302, y=470},
{x=407, y=470}, {x=512, y=470}, {x=617, y=470} }

for i=1, #alpha do
local selection = table.remove(coordinates, math.random(#coordinates))
print(selection.x,selection.y, #coordinates)
images = display.newImage(beta[i])
images.x = selection.x
images.y = selection.y
end
[/code] [import]uid: 82446 topic_id: 14226 reply_id: 63767[/import]