@@ -361,6 +361,29 @@ public class RiveView: UIView {
361361 runTimer ( )
362362 }
363363
364+ /// Plays the list of animations or state machines with optional loop and directions
365+ /// - Parameter animationNames: list of names of the animations to play
366+ /// - Parameter loop: overrides the animation's loop setting
367+ /// - Parameter direction: overrides the animation's default direction (forwards)
368+ /// - Parameter isStateMachine: true of the name refers to a state machine and not an animation
369+ public func play(
370+ animationNames: [ String ] ,
371+ loop: Loop = . loopAuto,
372+ direction: Direction = . directionAuto,
373+ isStateMachine: Bool = false
374+ ) {
375+ animationNames. forEach { animationName in
376+ _playAnimation (
377+ animationName: animationName,
378+ loop: loop,
379+ direction: direction,
380+ isStateMachine: isStateMachine
381+ )
382+ }
383+
384+ runTimer ( )
385+ }
386+
364387
365388 /// Pauses all playing animations and state machines
366389 public func pause( ) {
@@ -425,6 +448,21 @@ public class RiveView: UIView {
425448 return stateMachineInstances
426449 }
427450
451+ private func _getOrCreateLinearAnimationInstances(
452+ animationName: String
453+ ) -> [ RiveLinearAnimationInstance ] {
454+ let animationInstances = _animations ( animationName: animationName)
455+
456+ if ( animationInstances. isEmpty) {
457+ guard let guardedArtboard= _artboard else {
458+ return [ ]
459+ }
460+ let animationInstance = guardedArtboard. animation ( fromName: animationName) . instance ( )
461+ return [ animationInstance]
462+ }
463+ return animationInstances
464+ }
465+
428466 private func _playAnimation(
429467 animationName: String ,
430468 loop: Loop = . loopAuto,
@@ -437,23 +475,14 @@ public class RiveView: UIView {
437475 _play ( stateMachineInstance)
438476 }
439477 } else {
440- let animationInstances = _animations ( animationName: animationName)
478+ let animationInstances = _getOrCreateLinearAnimationInstances ( animationName: animationName)
441479
442480 animationInstances. forEach { animationInstance in
443481 _play (
444482 animation: animationInstance,
445483 loop: loop, direction: direction
446484 )
447485 }
448- if ( animationInstances. isEmpty) {
449- guard let guardedArtboard= _artboard else {
450- return
451- }
452- let animationInstance = guardedArtboard. animation ( fromName: animationName) . instance ( )
453-
454- _play ( animation: animationInstance, loop: loop, direction: direction)
455-
456- }
457486 }
458487 }
459488
0 commit comments