0

我有一个带有令牌的单词搜索游戏,用户可以使用它们来显示他们必须找到的单词。但我的问题是,在我单击标记后,我无法突出显示在单词搜索中找到的单词,而是每次单击时都会带走标记,无论在关卡的哪个位置。我试过 token:removeEventListener 但这不起作用,也许我把它放在了错误的位置

function token:touch( event )
if event.phase == "began" then
if storyboard.state.score >0 then
    storyboard.state.score = storyboard.state.score - 1
    score.text = tostring(storyboard.state.score)
    clueText.isVisible = false
    answerText.isVisible = true
    display.getCurrentStage():setFocus( event.target )
    event.target.isFocus = true
elseif event.target.isFocus then
    if event.phase == "moved" then
        print( "user has moved their finger off the token." )
    elseif event.phase == "ended" then
        print( "user has used a token" )
        display.getCurrentStage():setFocus( nil )
        event.target.isFocus = false
    end
end
return true
end
end
menubutton:addEventListener( "touch", menubutton)
token:addEventListener( "touch", token)

有任何想法吗?

4

2 回答 2

2

尝试像这样修改您的功能:

function tokenTouch( event )
    if event.phase == "began" then
        if storyboard.state.score >0 then
            storyboard.state.score = storyboard.state.score - 1
            score.text = tostring(storyboard.state.score)
            clueText.isVisible = false
            answerText.isVisible = true
            display.getCurrentStage():setFocus( event.target )
            event.target.isFocus = true
        end
    elseif event.target.isFocus then
        if event.phase == "moved" then
            print( "user has moved their finger off the token." )
        elseif event.phase == "ended" then
            print( "user has used a token" )
            display.getCurrentStage():setFocus( nil )
            event.target.isFocus = false
        end
    end
    return true
end
token:addEventListener( "touch", tokenTouch )
于 2013-04-22T09:07:09.340 回答
0

如果你想删除你的监听器。你必须在添加监听器之后添加删除监听器。

local function token(event)
                if event.phase == "began" then

                elseif event.phase == "moved" then

                elseif event.phase == "ended" then
                end
        return true
        end
        token:addEventListener("touch",token)


token:removeEventListener("touch",token)
于 2013-04-22T08:31:03.167 回答