0
我正在构建一个简单的游戏,玩家点击一个随机移动以获得分数的球。但是,当我测试我的游戏时,我意识到轻击功能无法正常工作。当我试图点击移动的球时,有时分数会增加,但有时候没有反应。这是我使用的代码。谢谢您的帮助!对于lua没有响应的点击事件
local ball = display.newImage("ball.png")
ball.x = math.random(0,w)
ball.y = math.random(0,h)
physics.addBody(ball)
function moveRandomly()
ball:setLinearVelocity(math.random(-50,50), math.random(-50,50));
end
timer.performWithDelay(500, moveRandomly, 0);
ball.rotation = 180
local reverse = 1
local function rotateball()
if (reverse == 0) then
reverse = 1
transition.to(ball, { rotation=math.random(0,360), time=500, transition=easing.inOutCubic })
else
reverse = 0
transition.to(ball, { rotation=math.random(0,360), time=500, transition=easing.inOutCubic })
end
end
timer.performWithDelay(500, rotateball, 0)
local myText, changeText, score
score = 0
function changeText(event)
score = score + 1
print(score.."taps")
myText.text = "Score:" ..score
return true
end
myText = display.newText("Score: 0", w, 20, Arial, 15)
myText:setFillColor(0, 1, 1)
myText:addEventListener("tap", changeText)
ball:addEventListener("tap", changeText)