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

Forge2DGame + PositionComponents inconsistent onGameResize() #1338

Closed
dmytro-me opened this issue Jan 24, 2022 · 3 comments · Fixed by #1337
Closed

Forge2DGame + PositionComponents inconsistent onGameResize() #1338

dmytro-me opened this issue Jan 24, 2022 · 3 comments · Fixed by #1337
Assignees
Labels

Comments

@dmytro-me
Copy link

I'm trying to add simple PositionComponent to the Forge2DGame and respond to the onGameResize calls.

Current bug behaviour

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_forge2d/forge2d_game.dart';
import 'package:flutter/material.dart';

class TestComponent extends PositionComponent {
  @override
  void onGameResize(Vector2 canvasSize) {
    print("child::gameSize: $canvasSize");
    super.onGameResize(canvasSize);
  }
}

class MyGame extends Forge2DGame {
  MyGame()
      : super(
          gravity: Vector2(0, -1.0),
          zoom: 10.0,
        );

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

  @override
  void onGameResize(Vector2 canvasSize) {
    print("game::gameSize: $canvasSize");
    super.onGameResize(canvasSize);
  }
}

main() {
  final myGame = MyGame();
  runApp(
    GameWidget(
      game: myGame,
    ),
  );
}

If I build and run the code above for the macosx target and try to resize game window the code produces this debug output:

flutter: game::gameSize: [1937.0,1089.0]
flutter: child::gameSize: [193.70000000000002,108.9]
flutter: game::gameSize: [1929.0,1082.0]
flutter: child::gameSize: [1929.0,1082.0]

Expected behaviour

As you can see the first onGameResize() call passes scaled (zoomed) size, but all following updates uses real window size. It's expected that output be consistent either scaled or not.

Steps to reproduce

build and run the code above for the macosx target and try to resize game window

Flutter doctor output

Output of: flutter doctor -v
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-x64, locale en-ES)
    • Flutter version 2.8.1 at /Volumes/Home/dmp/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Volumes/Home/dmp/Library/Android/sdk/
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Volumes/Home/dmp/Library/Android/sdk/
    • ANDROID_SDK_ROOT = /Volumes/Home/dmp/Library/Android/sdk/
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.32.0

[✓] Connected device (7 available)

More environment information

  • Flame version: 1.0.0
  • Platform affected: desktop, probably more

Log information

Enter log information in this code block

More information

@dmytro-me dmytro-me added the bug label Jan 24, 2022
@spydon spydon self-assigned this Jan 24, 2022
@spydon
Copy link
Member

spydon commented Jan 24, 2022

Oh, interesting, my guess is that this bug also affects the normal FlameGame?
Have you tried having a normal FlameGame zoomed in (or out) and added a component?

@dmytro-me
Copy link
Author

You are right, it doesn't specific to Forge2DGame , I'm getting pretty same results with

class MyGame extends FlameGame {
  MyGame() : super() {
    camera.zoom = 10.0;
  }

// Not sure if I set up camera right :)

flutter: game::gameSize: [1925.0,1077.0]
flutter: child::gameSize: [192.5,107.7]
flutter: game::gameSize: [1934.0,1080.0]
flutter: child::gameSize: [1934.0,1080.0]
flutter: game::gameSize: [1937.0,1082.0]
flutter: child::gameSize: [1937.0,1082.0]
flutter: game::gameSize: [1940.0,1083.0]

@spydon
Copy link
Member

spydon commented Jan 25, 2022

You are right, it doesn't specific to Forge2DGame

Thanks for checking, I'll have a closer look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants