在我试图制作的一款游戏中,瓷砖之间似乎有闪烁的白线.只有当我在移动时,闪烁的线条才会出现,因为相机正在移动.我正在使用:

Flutter :3.16.5

火焰:^1.13.1 Flam_forge2d:^0.16.0+3 FLAME_AUDIO:^2.1.6 火焰平铺:^1.18.2

我在之前的项目中使用了几乎相同的代码,在Android版本中没有遇到这个问题.然而,这一次,随着最新版本的一切,我在Android版本中面临着这个问题.我知道这在Web构建中很常见,我以前在Web上遇到过这个问题,但这是我第一次在Android中面对这个问题.如有任何帮助,我们将不胜感激!

flicker of white line after first platform block

flicker of white lines on tallest of stairs

class MapLevel extends Component with HasGameRef<MainGame> {
  MapLevel({required this.level}) : super();

  int level;

  late Vector2 mapSize;
  

  @override
  FutureOr<void> onLoad() async {
    TiledComponent map = await TiledComponent.load(
        'map$level.tmx', Vector2.all(32) / 10,
        priority: 20);
    add(map);
    mapSize = map.scaledSize;

    final spawnLayer = map.tileMap.getLayer<ObjectGroup>('spawn');

    final platformLayer = map.tileMap.getLayer<ObjectGroup>('platforms');

    for (final platform in platformLayer!.objects) {
      game.world.add(Platform(
        position: Vector2(platform.x / 10, platform.y / 10),
        size: Vector2(platform.width / 10, platform.height / 10),
      ));
    }

    for (final spawn in spawnLayer!.objects) {
      if (spawn.class_ == 'player') {
        var player = Player(
            spawnPosition: Vector2(spawn.x / 10, spawn.y / 10),
            size: Vector2(spawn.width / 10, spawn.height / 10) * 0.8);
        await game.world.add(player);
        game.player=player;
        game.camera.follow(player);
      }
    }

    game.camera.viewfinder.zoom = (game.canvasSize.x / mapSize.y);

    // game.player?.cameraFollow();
    return super.onLoad();
  }


  

}

推荐答案

这是游戏开发中的常见问题,不仅在Flutter和Flame中,它被称为鬼线,来自计算机中的浮点数不精确. 你可以在this issue中阅读更多关于它的内容,你可以在here中找到一个工作.

在解决方法中,您必须在瓷砖之间创建空的间距,因为舍入误差通常会使像素紧挨着它,如果我们向瓷砖添加间距,即使发生舍入误差,纹理采样也会拾取一个透明像素.

你可以用tile patcher tool来做这件事.

Flutter相关问答推荐

在Flutter中,CachedNetworks Image不工作(不从CachedData加载)

如何在不使用NULL-check(!)的情况下缩小`FutureBuilder.Builder()`内部的`Snaphot`范围

遇到图像路径格式问题

无法在仿真器上运行Flutter 项目-文件名太长错误

使用ImageFilter模糊并剪裁同一renderObject中的元素

参数类型';List<;Dynamic&>不能分配给参数类型';List<;SingleChildWidget&>';

Android工作室Flutter 热重新加载更新后不工作

如何在flutter中更改showModalBottomSheet小部件中CheckboxListTile小部件的值?

使用 flutter_svg 在 flutter 中的 Canvas 上绘制 SVG 图像

Select 文本时如何更改 Flutter 中的光标 colored颜色 ?

使用 Flutter 和 Dio 将图像上传到 API

围绕父组件旋转位置组件

输入处于活动状态时如何设置文本字段标签的样式?

小部件堆栈未显示顶层

Flutter blue plus 库,当try 从 esp32 驱动程序获取 PlatformException 时读取特性

flutter 在文本字段中更改部分文本选定 colored颜色

SfCircularChart 周围的额外间距

在 flutter 中自定义 agora 视频通话 UI

Flutter 本地通知在最新版本中不起作用

使用 mocktail 包进行单元测试时,类型Null不是Future类型的子类型