跳到主要内容

监听器动作接口(ListenerAction)

当关联的 状态机监听器(State Machine Listener) 被触发时执行的动作。

更多信息见:Listener Action Scripts

方法(Methods)​

init​

init(self: T, context: Context) -> boolean

监听器创建或附加时调用一次。

type MyListenerAction = {}

-- Called once when the script initializes.
function init(self: MyListenerAction, context: Context): boolean
return true
end

function perform(self: MyListenerAction, pointerEvent: PointerEvent) end

return function(): ListenerAction<MyListenerAction>
return {
init = init,
perform = perform,
}
end

perform​

perform(self: T, pointerEvent: PointerEvent) -> ()

关联的 状态机监听器(State Machine Listener) 触发时调用。 该方法包含 PointerEvent 参数,描述触发交互的细节。

已弃用。 请改用带 ListenerContext 的 performAction;此重载可能会被移除。

type MyListenerAction = {}

function init(self: MyListenerAction, context: Context): boolean
return true
end

-- Add your transition logic here.
function perform(self: MyListenerAction, pointerEvent: PointerEvent)
-- perform action here
end

-- Return a factory function that Rive uses to build the Listener Action instance.
return function(): ListenerAction<MyListenerAction>
return {
init = init,
perform = perform,
}
end

performAction​

performAction(self: T, listenerContext: ListenerContext) -> ()

关联的 状态机监听器(State Machine Listener) 触发时调用。 该方法包含 ListenerContext 参数,描述触发交互的细节。

type MyListenerAction = {}

function init(self: MyListenerAction, context: Context): boolean
return true
end

-- Called each time the listener fires.
function performAction(self: MyListenerAction, listenerContext: ListenerContext)
if listenerContext:isPointerEvent() then
print('clicked')
end
end

-- Return a factory function that Rive uses to build the Listener Action instance.
return function(): ListenerAction<MyListenerAction>
return {
init = init,
performAction = performAction,
}
end
看完还有疑问?进群交流下!
与众多 Rive 创作者、开发者一起交流探讨与答疑解惑。
加入交流群