Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update size of RectangleComponent after first paint #2178

Closed
lukepighetti opened this issue Nov 22, 2022 · 1 comment
Closed

Cannot update size of RectangleComponent after first paint #2178

lukepighetti opened this issue Nov 22, 2022 · 1 comment
Labels

Comments

@lukepighetti
Copy link
Contributor

TLDR: if you create a RectangleComponent, you cannot update it's size after first paint

class OffscreenCharacter extends PositionComponent with HasGameRef<MyGame> {
  OffscreenCharacter();

  /// REPRO: This paints at the correct size on first frame
  late final myRectangleComponent = RectangleComponent(
    anchor: Anchor.center,
    size: camera.gameSize,
    paint: Paint()..color = Colors.red.withOpacity(0.2),
  );

  @override
  Future<void>? onLoad() async {
    await add(myRectangleComponent);
    return super.onLoad();
  }

  late final camera = gameRef.camera;

  @override
  void onGameResize(Vector2 size) {
    super.onGameResize(size);

    /// REPRO: This is not able to update the size
    myRectangleComponent.size.setFrom(gameRef.size);
  }

  @override
  void update(double dt) {
    final cameraCenter = camera.position + camera.gameSize / 2;
    myRectangleComponent.position.setFrom(cameraCenter);
    super.update(dt);
  }
}

Reproduction available here: https://github.com/lukepighetti/plt/tree/lukepighetti/on-game-resize-repro

Discord thread here: https://discord.com/channels/509714518008528896/1044629513000194138

@spydon
Copy link
Member

spydon commented Nov 23, 2022

This is solved by #2167

@spydon spydon closed this as completed Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants