Flutter 中收集金币动画【神庙逃亡金币收集】

问题描述 投票:0回答:1

我想在Flutter中实现以下动画。我将感谢你们所有人的资源。

参考:8球台球游戏金币动画。

动画:

这是 Lottie 动画中的另一个示例:

https://lottiefiles.com/animations/coin-collect-GMznH8RzOB

我尝试在没有视觉特效艺术家帮助的情况下四处寻找。

flutter animation flutter-animation
1个回答
1
投票

我做到了🤓。尝试自己定制。

class CoinAnimation extends StatefulWidget {
  const CoinAnimation({super.key});

  @override
  _CoinAnimationState createState() => _CoinAnimationState();
}

class _CoinAnimationState extends State<CoinAnimation>
    with TickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _opacityAnimation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 1000),
    )
      ..forward()
      ..addListener(() {
        if (_controller.isCompleted) {
          _controller.repeat();
        }
      });

    _opacityAnimation = Tween(begin: 1.0, end: 0.0).animate(
      CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
    );

    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Coin Animation'),
      ),
      body: Center(
        child: AnimatedBuilder(
          animation: _controller,
          builder: (context, child) {
            return Stack(
              alignment: Alignment.center,
              children: [
                // Coins icon
                const Icon(
                  Icons.attach_money,
                  size: 100,
                ),
                // Flashing light effect
                Opacity(
                  opacity: _opacityAnimation.value,
                  child: Container(
                    width: 200,
                    height: 200,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      gradient: RadialGradient(
                        colors: [
                          Colors.yellow.withOpacity(0.7),
                          Colors.transparent
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            );
          },
        ),
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.