Skip to main content
Node scripts can be used to render shapes, images, text, artboards, and more. A scripted node can be attached to any Node and is rendered in the local transform space of the hosting Node. For more information, see Node Scripts.

Methods

init

Called once when the node is created. Returns true if initialization succeeds. For a more complete example using init, see Instantiating Components.
-- Define the script's data and inputs.
type MyNode = {}

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

-- Return a factory function that Rive uses to build the Node instance.
return function(): Node<MyNode>
  return {
    init = init
  }
end

advance

Optional per-frame update. Returns true if the node should continue receiving advance calls. For a more complete example using advance, see Fixed-step Advanced.
-- Define the script's data and inputs.
type MyNode = {}

-- Called every frame to advance the simulation.
-- 'seconds' is the elapsed time since the previous frame.
function advance(self: MyNode, seconds: number): boolean
  return false
end

-- Return a factory function that Rive uses to build the Node instance.
return function(): Node<MyNode>
  return {
    advance = advance,
  }
end

update

Called when an input value changes.
-- Define the script's data and inputs.
type MyNode = {}

-- Called when any input value changes.
function update(self: MyNode)
  print('An script input value has changed.')
end

-- Return a factory function that Rive uses to build the Node instance.
return function(): Node<MyNode>
  return {
    update = update,
  }
end

draw

Called to render the node using the provided Renderer. For a more complete example using draw, see Instantiating Components.
-- Define the script's data and inputs.
type MyNode = {}

-- Called every frame (after advance) to render the content.
function draw(self: MyNode, renderer: Renderer) end

-- Return a factory function that Rive uses to build the Node instance.
return function(): Node<MyNode>
  return {
    draw = draw,
  }
end

pointerDown

Pointer event down handler.
function handlePointerDown(self: MyGame, event: PointerEvent)
  print('Pointer Position: ', event.position.x, event.position.y)

  event:hit()
end

return function(): Node<MyGame>
    return {
        init = init,
        advance = advance,
        draw = draw,
        pointerDown = handlePointerDown,
    }
end

pointerMove

Pointer event move handler.
function handlePointerMove(self: MyGame, event: PointerEvent)
  print('Pointer Position: ', event.position.x, event.position.y)

  event:hit()
end

return function(): Node<MyGame>
    return {
        init = init,
        advance = advance,
        draw = draw,
        pointerMove = handlePointerMove,
    }
end

pointerUp

Pointer event up handler.
function handlePointerUp(self: MyGame, event: PointerEvent)
  print('Pointer Position: ', event.position.x, event.position.y)

  event:hit()
end

return function(): Node<MyGame>
    return {
        init = init,
        advance = advance,
        draw = draw,
        pointerUp = handlePointerUp,
    }
end

pointerExit

Pointer event exit handler.
function handlePointerExit(self: MyGame, event: PointerEvent)
  print('Pointer Position: ', event.position.x, event.position.y)

  event:hit()
end

return function(): Node<MyGame>
    return {
        init = init,
        advance = advance,
        draw = draw,
        pointerExit = handlePointerExit,
    }
end