flame
flame copied to clipboard
camera break the screenhitbox
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));
}
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
I'm closing this as inactive.