0

我正在尝试匹配 Corona 上的图像。我创建了图像并匹配数组变量并将显示对象插入到这些数组中。但是,我无法弄清楚如何将相同的对象之一移动到另一个对象上并使其消失。你能帮我吗?谢谢。

到目前为止,这是我的代码:

    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
4

1 回答 1

1

为每个图像分配类型等是最简单的,例如;{img="img1.png" , x=30, y=30, type="red" }

然后,当它被释放时,使用 object.contentBounds 检查它是否在其他参数表中匹配图像的内容范围内(您可以在 Corona Labs API 页面上找到有关此的详细信息。)

于 2012-07-07T09:41:15.580 回答