/
username0273
/
TextAdventure
Обзор
Документация
Войти
/
username0273
/
TextAdventure
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/main/java/com/example/textadventure/utils/AnimationManager.kt
80 строк
3 KB
Simon
first_commit
22 апр 2026, 23:38
22 апр 2026, 23:38
ea68305
Код
Авторство
О чём код?
package com.example.textadventure.utils import android.view.View import android.view.animation.Animation import android.view.animation.ScaleAnimation import android.view.animation.TranslateAnimation class AnimationManager { companion object { // ----------------------------------------------------------------------------------------- // shake animation for taking damage // ----------------------------------------------------------------------------------------- fun takeDamageAnimation(view: View) { val anim = TranslateAnimation(0f, -20f, 0f, 0f).apply { duration = 50 repeatCount = 3 repeatMode = Animation.REVERSE setAnimationListener(object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation) {} override fun onAnimationEnd(animation: Animation) {} override fun onAnimationRepeat(animation: Animation) {} }) } view.startAnimation(anim) } // ----------------------------------------------------------------------------------------- // scale up and down for attack // ----------------------------------------------------------------------------------------- fun attackAnimation(view: View) { val scaleUp = ScaleAnimation( 1.0f, 1.4f, // X scale 1.0f, 1.4f, // Y scale Animation.RELATIVE_TO_SELF, 0.5f, // Pivot X Animation.RELATIVE_TO_SELF, 0.5f // Pivot Y ).apply { duration = 200 fillAfter = false } val scaleDown = ScaleAnimation( 1.4f, 1.0f, 1.4f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f ).apply { duration = 200 startOffset = 200 setAnimationListener(object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation) {} override fun onAnimationEnd(animation: Animation) {} override fun onAnimationRepeat(animation: Animation) {} }) } view.startAnimation(scaleUp) view.postDelayed({ view.startAnimation(scaleDown) }, 200) } // ----------------------------------------------------------------------------------------- // quick side step animation for dodge // ----------------------------------------------------------------------------------------- fun dodgeAnimation(view: View) { val dodge = TranslateAnimation(0f, -100f, 0f, 0f).apply { duration = 180 repeatCount = 1 repeatMode = Animation.REVERSE setAnimationListener(object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation) {} override fun onAnimationEnd(animation: Animation) {} override fun onAnimationRepeat(animation: Animation) {} }) } view.startAnimation(dodge) } } }