GithubHelp home page GithubHelp logo

Comments (10)

erickzanardo avatar erickzanardo commented on May 5, 2024 3

We are still investigating why this happens, but the problem is not with Flame.util.initialDimensions, this seems to return correctly. But looks like the game widget does not knows how to proper resize itself when the correct metrics is set.

But I have found a good workaround, you can call and await initialDimensions on your main function before calling runApp, and then just pass the size to your game instance.

Something like this: bluefireteam/bob_box@6b07746

from flame.

erickzanardo avatar erickzanardo commented on May 5, 2024

Like the issue says, there is indeed differences between the debug and release mode. Is you need the screensize, please use Flame.util.initialDimensions.

from flame.

a-gms avatar a-gms commented on May 5, 2024

This is example faulty code:
`
SampleGame demo;
Widget w;

void main() {
demo = SampleGame();
w = demo.widget;
start(() => Wrapper());
}

class Wrapper extends StatefulWidget {
@OverRide
_WrapperState createState() => _WrapperState();
}

class _WrapperState extends State {
_WrapperState() {
window.onMetricsChanged = () {
print("on metrics changed");
};
}

@OverRide
Widget build(BuildContext context) {
return demo.widget;
}
}
`
When I remove setting window.onMetricsChanged it works fine. Seems like Flame is setting this listener and if it is set somewhere else in user code then Flame doesn't worek properly.

from flame.

erickzanardo avatar erickzanardo commented on May 5, 2024

Yeah, Flame uses onMetricsChanged on that helper method that I sent you earlier: https://github.com/luanpotter/flame/blob/709e52e04dbf6239b4e322f7cbc77c1a9986600e/lib/util.dart#L41

Do you need to use this listener for some reason? If this is the case we could wrap it somehow and provide a way to set this listener and keep Flame.util.initialDimensions working

from flame.

a-gms avatar a-gms commented on May 5, 2024

Now that I know about this, I can avoid setting this listener, but some unaware user might spend time figuring it out. For example onMetricsChanged listener is set in main menu screen built with standard flutter widgets. Then a next page containing Flame is opened and silently replaces this global listener. Too bad its not a list.

from flame.

ecklf avatar ecklf commented on May 5, 2024

Having the same issue even if using Flame.util.initialDimensions
Code: https://github.com/impulse/flutters/blob/master/lib/flutters-game.dart#L44

❯ flutter doctor -v

[✓] Flutter (Channel beta, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale en-DE)
• Flutter version 1.5.4-hotfix.2 at /Users/lynx/Development/flutter
• Framework revision 7a4c33425d (2 weeks ago), 2019-04-29 11:05:24 -0700
• Engine revision 52c7a1e849
• Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/lynx/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/lynx/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• ios-deploy 1.9.4
• CocoaPods version 1.6.1

[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

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

from flame.

ecklf avatar ecklf commented on May 5, 2024

I can confirm that the workaround by awaiting prior to runApp works!

from flame.

erickzanardo avatar erickzanardo commented on May 5, 2024

@impulse did you confirmed if this is still happening?

from flame.

ecklf avatar ecklf commented on May 5, 2024

@erickzanardo didn't run into the issue again in the newer flame versions (tested it on 2 devices). I think we can close this.

from flame.

erickzanardo avatar erickzanardo commented on May 5, 2024

Awesome news, going to close it then, Thanks!

from flame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.