Lua 在corona中删除并再次添加运行时事件侦听器

Lua 在corona中删除并再次添加运行时事件侦听器,lua,coronasdk,Lua,Coronasdk,我在这里想要实现的是。。。如果我触摸一个图像,它将被禁用。然后我想通过触摸另一个图像来启用它。但禁用后,我无法重新启用它。 我有一个触摸事件的第一个图像,我调用使用 Runtime:addEventListener( "touch", diceFunction2 ) 我使用 Runtime:removeEventListener( "touch", diceFunction2 ) 但是我尝试使用这个触摸事件处理程序再次添加它 local function guti11touched( e

我在这里想要实现的是。。。如果我触摸一个图像,它将被禁用。然后我想通过触摸另一个图像来启用它。但禁用后,我无法重新启用它。 我有一个触摸事件的第一个图像,我调用使用

Runtime:addEventListener( "touch", diceFunction2 ) 
我使用

Runtime:removeEventListener( "touch", diceFunction2 ) 
但是我尝试使用这个触摸事件处理程序再次添加它

local function guti11touched( event )
  if event.phase == "began" then
     if playerTurn%2==0 then
        if rand == 6 and gutiStatus.guti11.status == false then
            gutiStatus.guti11.status = true
            gutiStatus.guti11.count = 1
            local i = gutiStatus.guti11.count
            transition.moveTo(guti11, {x=background.x+player1Sequence[i][1],y=background.y-player1Sequence[i][2]})
        elseif gutiStatus.guti11.status == true and gutiStatus.guti11.count+rand <= 57 then
            gutiStatus.guti11.count = gutiStatus.guti11.count + rand
            local i = gutiStatus.guti11.count
            transition.moveTo(guti11, {x=background.x+player1Sequence[i][1],y=background.y-player1Sequence[i][2]})
            if i == 57 then
                guti11.isClickable = false
            end
        end
     end
  elseif event.phase == "ended" then
    Runtime:addEventListener( "touch", diceFunction2 ) 
  end
return true
end
这是我的旋转函数

local function rotateDice()
  dice.rotation = dice.rotation + 200
end 

运行时触摸处理程序覆盖整个屏幕。如果要在对象上创建触摸事件,通常会将触摸事件直接添加到该对象:

someImage:addEventListener(“触摸”,myTouchFunction)


然后,我就不用担心添加和删除侦听器,而是设置一些标志,指示是否允许触摸。

在我的情况下,我没有处理特定的图像,当我单击一个图像时,它会随机更改为另一个图像。所以我不确定我是否可以使用someImage:addEventListener(“touch”,myTouchFunction)我已经用函数更新了我的问题,请看一看我将touch事件添加到了对象并设置了标志,但我不得不对代码进行了大量修改,但最终成功了。谢谢你的建议,我建议你使用雪碧。您将有一个具有6帧的显示对象,一个用于骰子的每个面。然后你只需更改显示的帧。好的,再次感谢。。。我也会尝试用精灵来做这件事……谢谢你的建议……如果我成功了,我会告诉你的D
local function rotateDice()
  dice.rotation = dice.rotation + 200
end