Use this file to discover all available pages before exploring further.
Linear animations are timeline-based animations created in the Rive editor. They play from a start point to an end point and can loop, ping-pong, or play once.
The RiveLinearAnimationInstance class represents a playable instance of a linear animation. It provides fine-grained control over playback, timing, direction, and loop modes.
do { let file = try RiveFile(name: "truck") let artboard = try file.artboard() // Get animation by name let animation = try artboard.animation(fromName: "idle") // Get animation by index let firstAnimation = try artboard.animation(from: 0) // List available animations let names = artboard.animationNames() print("Available animations: \(names)")} catch { print("Error loading animation: \(error)")}
do { let model = try RiveModel(fileName: "truck") // Set animation by name try model.setAnimation("idle") // Set animation by index (defaults to 0) try model.setAnimation() // Access the animation instance let animation = model.animation} catch { print("Error setting animation: \(error)")}
// Get current timelet currentTime = animation.time()// Set specific timeanimation.setTime(2.5) // Jump to 2.5 seconds// Get end timelet endTime = animation.endTime()print("Animation ends at: \(endTime)s")
// Check if animation has endedif animation.hasEnded() { print("Animation finished")}// Check if animation looped in the last frameif animation.didLoop() { print("Animation just looped")}
// Get current loop modelet currentLoop = animation.loop()// Set loop modeanimation.loop(RiveLoop.oneShot.rawValue) // Play onceanimation.loop(RiveLoop.loop.rawValue) // Loop continuouslyanimation.loop(RiveLoop.pingPong.rawValue) // Ping-pong back and forthanimation.loop(RiveLoop.autoLoop.rawValue) // Use editor settings
// Get current directionlet currentDirection = animation.direction()// Set directionanimation.direction(RiveDirection.forwards.rawValue) // Play forwardsanimation.direction(RiveDirection.backwards.rawValue) // Play backwardsanimation.direction(RiveDirection.autoDirection.rawValue) // Use editor settings