首页 文章

使用颤动/飞镖翻转和摇动瓷砖动画?

提问于
浏览
1

https://github.com/chimple/maui/blob/master/lib/games/memory.dart

我正在尝试使用Flutter / Dart实现MemoryMatching游戏 . 整个游戏逻辑已被编码Up..only动画正在等待当用户点击任何随机的瓷砖翻转瓦片时,并且在尝试匹配不匹配的瓦片时,应该发生摇动动画,并且它们应该再次翻转 . These is how initial look of the game

1 回答

  • 1

    this页面上有一个如何制作自定义摇动曲线的示例 .
    它还详细介绍了如何使用曲线创建动画 .

    编辑:实际上我试过这个,示例曲线导致颤动错误 . 你可以做的是使用这样的变换;

    /// create and animation controller in your init state;
    _controller = new AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 1000),
    )..addListener(()=>setState((){}));
    
    ...
    
    ///wrap your layout in a transform;
    return Transform(
        transform: Matrix4.translation(getTranslation()),
        child:
          /*your layout widget here*/,
      );
    
    ///Then you can get a shake type motion like so;
    Vector3 getTranslation() {
      double progress = _controller.value;
      double offset = sin(progress * pi * 2);
      return v.Vector3(offset, 0.0, 0.0);
    }
    

    然后,一旦你在动画控制器上调用前进,你将获得一个很好的摇动效果 . 获得更明显的抖动乘以一个常数的偏移量 . 为了获得更快的震动,将2.0更改为更高的量 .

    接受的答案here描述了翻转动画的简单解决方案

相关问题