LibGDX | Android | LottieAnimation
Инструкция по добавлению LottieAnimation Loader-ов в LibGDX (только Android)
Проэкт построен по статье:
По этому для полного понимания происходящего, паралельно откройте эту статью.
- Добавляем необходимые зависимость:
bild.gradle(:app)/dependencies:
def coroutines_version = '1.5.2'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
def lottie_version = '4.2.2'
implementation "com.airbnb.android:lottie:$lottie_version"
2. Добавляем LottieAnimationView:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent=".9" />
3. Создаем класс Loader:
object Loader {
private val coroutineAnimation = CoroutineScope(Dispatchers.Main)
fun show(@RawRes animationId: Int) {
coroutineAnimation.launch {
binding.lottie.apply {
isVisible = true
setAnimation(animationId)
repeatCount = LottieDrawable.INFINITE
playAnimation()
}
}
}
fun hide() {
coroutineAnimation.launch {
binding.lottie.apply {
isVisible = false
cancelAnimation()
}
}
}
}
3. Скачайте анимации с сайта: https://lottiefiles.com/featured и поместите их в res/raw:
4. Используем Loader:
Вот и всё ✌️
PS. Vel_daN: Love what You DO 💚.