pknjigvfvl
pknjigvfvl

Reputation: 1

How to find the dimensions of screen in Flutter Flame Game without Camera?

I have a Flame Game app that I want to adjust to make it available on all kinds of screens, but my app doesn't use a world or camera. All of the solutions that I've found for finding screen size in Flutter seem to use these items. I don't need a world or camera, but I don't know if there's a way that I can find the screen size without it?

I've tried researching this, but can only find solutions using world or camera.

Upvotes: 0

Views: 1120

Answers (1)

spydon
spydon

Reputation: 11512

tYou can get the size of the canvas by just checking the size variable in your FlameGame class. (gameRef.size if you want to use it from a Component that has the HasGameRef mixin)

There is a built-in camera in the FlameGame class if you want to apply a FixedResolutionViewport, which sounds like what you want to do? This is the only line you have to add to do that, preferably in your game class's onLoad method:

camera.viewport = FixedResolutionViewport(Vector2(800, 600));

Upvotes: 0

Related Questions