* @param {number} index - animation index
(index)
| 441 | * @param {number} index - animation index |
| 442 | */ |
| 443 | setAnimation(index) { |
| 444 | const { _spine: spine } = this; |
| 445 | const configuration = gd.asSpineConfiguration( |
| 446 | this._associatedObjectConfiguration |
| 447 | ); |
| 448 | |
| 449 | if ( |
| 450 | !spine || |
| 451 | configuration.hasNoAnimations() || |
| 452 | index === this._animationIndex |
| 453 | ) { |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | if (!Number.isInteger(index) || index < 0) { |
| 458 | index = 0; |
| 459 | } else if (configuration.getAnimationsCount() <= index) { |
| 460 | index = configuration.getAnimationsCount() - 1; |
| 461 | } |
| 462 | |
| 463 | this._animationIndex = index; |
| 464 | const animation = configuration.getAnimation(index); |
| 465 | const source = animation.getSource(); |
| 466 | const shouldLoop = animation.shouldLoop(); |
| 467 | |
| 468 | // reset scale to track new animation range |
| 469 | // if custom size is set it will be reinitialized in update method |
| 470 | spine.scale.set(1, 1); |
| 471 | spine.state.setAnimation(0, source, shouldLoop); |
| 472 | const newTrack = spine.state.tracks[0]; |
| 473 | if (newTrack) newTrack.trackTime = 0; |
| 474 | spine.update(0); |
| 475 | spine.autoUpdate = false; |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * @returns {number} default width |
no test coverage detected