【发布时间】:2013-12-08 22:25:01
【问题描述】:
我在这里想要实现的是……如果我触摸一张图像,它就会被禁用。然后我想通过触摸另一个图像来启用它。但禁用后我无法重新启用它。 我有一个触摸事件用于我调用的第一张图片
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
有人可以告诉我正确的方法是什么,我做错了什么。
编辑
这是我的第一个图像事件处理程序。我已经尝试通过添加 dice:addEventListener( "touch", diceFunction2 ) ,但在这种情况下,图像只是保持旋转并且永不停止,并且因为我随机选择图像,所以我可以代替运行时这样做吗?
--for rotating dice
local function diceFunction2( event )
if event.phase == "began" then
local laserChannel = audio.play( laserSound )
rand=math.random(6)
dice = display.newImage("images/dice3droll.png")
dice.x = 75
dice.y = 480
dice:scale(1/scale_factor,1/scale_factor)
display.getCurrentStage():setFocus( dice )
dice.isFocus = true
Runtime:addEventListener( "enterFrame", rotateDice )
elseif dice.isFocus then
if event.phase == "moved" then
elseif event.phase == "ended" then
if rand == 1 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice1 = display.newImage("images/ek.png")
dice1.x = 75
dice1.y = 480
dice1:addEventListener( "touch", diceFunction2 )
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
elseif rand == 2 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice2 = display.newImage("images/dui.png")
dice2.x = 75
dice2.y = 480
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
elseif rand == 3 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice3 = display.newImage("images/tin.png")
dice3.x = 75
dice3.y = 480
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
elseif rand == 4 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice4 = display.newImage("images/charr.png")
dice4.x = 75
dice4.y = 480
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
elseif rand == 5 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice5 = display.newImage("images/pach.png")
dice5.x = 75
dice5.y = 480
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
elseif rand == 6 then
Runtime:removeEventListener( "enterFrame", rotateDice)
dice:removeSelf()
local dice6 = display.newImage("images/chokka.png")
dice6.x = 75
dice6.y = 480
display.getCurrentStage():setFocus( nil )
dice.isFocus = false
end
end
end
end
这是我的旋转功能
local function rotateDice()
dice.rotation = dice.rotation + 200
end
【问题讨论】: