Basically I have two tables one for the "words" and other for the "imgbtn".
I have placed 4 images in display and now I want those images to move around using touch how can i do it ?coz the one that i am doing is not working?please help me out I need it desperately.pleasee....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | local function match( event) if(event.phase == "began") then imgbtn[count].x=event.x imgbtn[count].y=event.y end end for count = 1,2 do x = x + 250 y = 0 for insideCount = 1,2 do y = y + 250 totalButtons = totalButtons + 1 temp = math.random(1,#words) imgbtn[count] = display.newImage(words[temp] .. ".jpg"); imgbtn[count].x = x imgbtn[count].y = y imgbtn[count].myName = words[temp] imgbtn[count].number = totalButtons table.remove(words, temp) imgbtn[count]:addEventListener( "touch", match) end end |
You're only setting the x/y properties of the image to event.x/event/y in the "began" phase of the event. You'll also need to do this in the "moved" phase. To ensure that the image "keeps up" with the touch, you should also look into the setFocus() function - check it out in the Corona API reference.