Comments (10)
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.
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.
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.
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.
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.
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.
I can confirm that the workaround by awaiting prior to runApp works!
from flame.
@impulse did you confirmed if this is still happening?
from flame.
@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.
Awesome news, going to close it then, Thanks!
from flame.
Related Issues (20)
- Flatpak HOT 1
- JoystickComponent onLoad no longer works starting v1.15 HOT 1
- Rays outside a CircleHitbox are seen by RaycastResult as inside. HOT 3
- Keyboard not working when resizing the web HOT 5
- Support dynamic changes to the layer opacity on tiled maps
- Tilemaps error occuring on Chrome mobile HOT 2
- ZigZagController with ColorEffect causes an exception HOT 4
- TextBoxComponent with typer text shows pink image before rendering text HOT 5
- SpriteWidget has unused parameters HOT 1
- Anchor is invalid when transform by matrix4 ?
- Klondike Tutorial, Step 5: Add code and further explanation of FlatButton and others, or at least a link to its code #19 HOT 6
- Strange phenomenon in flame rendering text HOT 7
- Convert ClipComponent factory Constructor to redirecting Constructor. HOT 1
- Unable scroll the text of the ScrollTextBoxComponent if I do not use timePerChar HOT 1
- Can not find asset when Flame Game is used as a module or package HOT 8
- texture packer can't override images HOT 6
- I'd like to call the child onRemove. HOT 4
- Add onComplete callback to ScrollTextBoxComponent HOT 2
- Flame + Forge2D + Riverpod == broken? HOT 1
- Change `Forge2DGame`'s `cameraComponent` constructor parameter to `camera` for consistency with `FlameGame`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flame.