flame icon indicating copy to clipboard operation
flame copied to clipboard

camera break the screenhitbox

Open denghejun opened this issue 3 years ago • 1 comments

When I add some code camera related, I found my player can break though the bound of the worldBounds, it looks like the ScreenHitbox feature was broken.

@override
  Future<void> onLoad() async {
    spriteImage = await Flame.images.load('player/player1.png');
    final image = await images.load('player/joystick.png');
    final sheet = SpriteSheet.fromColumnsAndRows(
      image: image,
      columns: 6,
      rows: 1,
    );
    add(ScreenHitbox()..debugMode = true);
    joystick = JoystickComponent(
      knob: SpriteComponent(
        sprite: sheet.getSpriteById(1),
        size: Vector2.all(100),
      ),
      background: SpriteComponent(
        sprite: sheet.getSpriteById(0),
        size: Vector2.all(150),
      ),
      margin: const EdgeInsets.only(left: 40, bottom: 40),
    );
    player = JoystickPlayer(joystick);

    add(Map());
    add(player);
    add(joystick);

    camera.viewport = FixedResolutionViewport(Vector2(500,500));
    camera.speed = 1;
    camera.followComponent(player, worldBounds: Rect.fromLTWH(0, 0, 1000, 1000));
  }

denghejun avatar May 18 '22 10:05 denghejun

I can't reproduce this on the Joystick Advanced example by adding a ScreenHitbox and followComponent on player. Have you tried this on main? It should :tm: be following the camera: https://github.com/flame-engine/flame/blob/main/packages/flame/lib/src/collisions/hitboxes/screen_hitbox.dart#L21

spydon avatar Jun 04 '22 15:06 spydon

I'm closing this as inactive.

spydon avatar Sep 17 '22 13:09 spydon