lateUpdate

类型 事件
修订 版本 2024.3703
关键词 lateUpdate, 运行时
另请参阅 基本的交互和事件检测 (指南)

概述

"lateUpdate" 事件在应用程序的帧率间隔发生,即 config.lua 中指定的 30 或 60。它们仅调度到全局 运行时 对象。

这在 "enterFrame" 事件之后,以及引擎开始渲染过程之前调度。因此,根据其状态进行任何最终更新非常有用。此外,对于所有监听此事件的人来说,它应该是一个安全的调用,否则,它将失去其目的。

属性

event.name

event.time

示例

local shouldUpdate = false
local rect = display.newRect(100, 100, 30, 30)
local x, y

-- Change the state
local touchListener = function( event )
    x, y = event.x, event.y
    shouldUpdate = true

    print("I need to update my position.") -- This could be call more than once each frame.
    
    return true
end 
rect:addEventListener("touch", touchListener)


-- Interpretation of the new state
local myListener = function( event )
    if not shouldUpdate then return false end
    shouldUpdate = false

    rect.x, rect.y = x, y

    print("Position updated!") -- This is going to be called just once, before the game renders.
end
Runtime:addEventListener( "lateUpdate", myListener )