Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i check if one of the same images is dragged and dropped on the other one in Corona?
    text
    copied!<p>I am trying to match images on Corona. I created images and matches array variables and insert the display objects inside those arrays. However, i can't figure it out how i will be able to move one of the same objects onto other and make it disappear. Can you help me out? Thanks.</p> <p>Here is my code so far:</p> <pre><code> local images={} local matches={} local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) t.isFocus = true elseif t.isFocus then if "moved" == phase then t.x = event.x t.y = event.y elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false end end return true end local arguments = { {img="img1.png" , x=30, y=30 }, {img="img2.png", x=100, y=30}, {img= "img3.png",x=170, y=30}, } local arguments2={ {img= "img1.png",x=30, y=150}, {img= "img2.png",x=100, y=150}, {img= "img3.png",x=170, y=150} } for _,item in ipairs( arguments ) do local imgg = display.newImage( item.img,item.x,item.y ) table.insert(images,imgg) -- Make the button instance respond to touch events imgg:addEventListener( "touch", onTouch ) end for _,item in ipairs( arguments2 ) do local imgg = display.newImage( item.img,item.x,item.y ) table.insert(matches,imgg) -- Make the button instance respond to touch events imgg:addEventListener( "touch", onTouch ) end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload