Allows you to run code once for every frame the display will render. This is a way of programming in “immediate mode” with Prototope.

let firstTimestamp = Timestamp.currentTimestamp
Heartbeat { heartbeat
    someLayer.x = sin(heartbeat.currentTimestamp - firstTimestamp) * 100 + 200
}
new Heartbeat({handler: function(heartbeat) {
    someLayer.x = Math.sin(heartbeat.currentTimestamp) * 100 + 200
}})

Method reference

  • public init(handler: Heartbeat -> ())new Heartbeat({handler: Function(heartbeat: Heartbeat)})

    You make a heartbeat with a closurefunction that specifies what should happen every frame.

    The heartbeat itself is passed into that handler so that you can determine the frame’s timestamp or cause the heartbeat to stop from within the handler.

  • public func stop()

    Permanently stops the heartbeat. Its handler won’t be invoked again.

  • Variables

  • public var paused: Boolthis.pausedBoolean

    The Heartbeat’s handler won’t be called when paused is true.

    Defaults to false.

  • public var timestamp: Timestampthis.timestampNumber

    The timestamp of the last frame that was displayed. Only valid to call from inside the Heartbeat’s handler block.

    You generally want to use this timestamp to do animations or to do other time math in your heartbeat, instead of using Timestamp.currentTimestamp: these timestamps will be spaced at regular 16.67ms intervals, whereas Timestamp.currentTimestamp will return a value that will vary depending on when it’s called in the time between frames being rendered.