1

I am trying to make a game in Corona which involves hitting the ball in a certain direction using the force vector. I am trying to trigger an event when the ball stops. I cannot use the "touch" event as the touch event is called several times when I touch the ball and set the direction for releasing it.

4

3 回答 3

4

您可以使用 Corona 的自定义事件在发生某些事情时调度您的事件,例如当球停止时。下面的代码将向 Runtime 对象分派一个事件。

local event = { name = "ballHasStoppedMoving", target = Runtime }
Runtime:dispatchEvent( event )

以下代码将用于侦听“ballHasStoppedMoving”事件并在事件触发时调用您的函数“ballStoppedMoving”。

local function ballStoppedMoving(event)

    print("The ball has stopped moving")

end

Runtime:addEventListener("ballHasStoppedMoving", ballStoppedMoving)
于 2012-09-24T21:19:17.363 回答
0

使用touch eventphase的属性,并且只在“开始”阶段做出反应。

于 2012-04-23T20:17:16.513 回答
0

在 enterFrame 事件中,使用 ball.getLinearVelocity 检查球的速度。如果它们不等于 (0,0),则执行方法/事件。如果您此时要执行自定义事件,请按照迈克尔的回答。

于 2012-09-24T21:41:46.847 回答