-
-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding on game resize example (#3260)
Simple example to test the `onGameResize` lifecycle method. https://github.com/user-attachments/assets/e0a874e9-f1f8-4fc3-b9bd-11a726a22794
- Loading branch information
1 parent
bf9a248
commit 4af00c1
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
class ResizingRectangle extends RectangleComponent { | ||
ResizingRectangle() | ||
: super( | ||
paint: Paint()..color = const Color(0xFFFE4813), | ||
); | ||
|
||
@override | ||
void onGameResize(Vector2 size) { | ||
super.onGameResize(size); | ||
|
||
this.size = size * .4; | ||
} | ||
} | ||
|
||
class ResizeExampleGame extends FlameGame { | ||
ResizeExampleGame() : super(children: [ResizingRectangle()]); | ||
|
||
static const description = ''' | ||
This example shows how to react to the game being resized. | ||
The rectangle will always be 40% of the screen size. | ||
Try resizing the window and see the rectangle change its size. | ||
'''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters