mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +08:00
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
49 lines
1.1 KiB
Dart
49 lines
1.1 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
class MyComponent extends PositionComponent {
|
|
String name;
|
|
@override
|
|
Vector2 size = Vector2(2.0, 2.0);
|
|
Vector2 gameSize;
|
|
|
|
MyComponent(this.name);
|
|
|
|
@override
|
|
void onGameResize(Vector2 gameSize) {
|
|
super.onGameResize(gameSize);
|
|
this.gameSize = gameSize;
|
|
}
|
|
}
|
|
|
|
class MyGame extends BaseGame {}
|
|
|
|
Vector2 size = Vector2(1.0, 1.0);
|
|
|
|
void main() {
|
|
group('resizable test', () {
|
|
test('game calls resize on add', () {
|
|
final MyComponent a = MyComponent('a');
|
|
final MyGame game = MyGame();
|
|
game.onResize(size);
|
|
game.add(a);
|
|
expect(a.gameSize, size);
|
|
});
|
|
test('game calls resize after added', () {
|
|
final MyComponent a = MyComponent('a');
|
|
final MyGame game = MyGame();
|
|
game.add(a);
|
|
game.onResize(size);
|
|
expect(a.gameSize, size);
|
|
});
|
|
test("game calls doesn't change component size", () {
|
|
final MyComponent a = MyComponent('a');
|
|
final MyGame game = MyGame();
|
|
game.add(a);
|
|
game.onResize(size);
|
|
expect(a.size, isNot(size));
|
|
});
|
|
});
|
|
}
|