mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
* Draft of PositionComponent.scale * Use matrix transformations * Update tests to take matrix transform into consideration * Add tests for collision detection with scale * Rename ScaleEffect to SizeEffect * Use transform matrix to prepare canvas * Fix scaledSizeCache * Add changelog entries and docs * Dartdoc on public access methods * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Move cache classes to own directory Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
61 lines
1.4 KiB
Dart
61 lines
1.4 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
|
|
class Square extends PositionComponent {
|
|
Square(Vector2 position, Vector2 size, {double angle = 0})
|
|
: super(
|
|
position: position,
|
|
size: size,
|
|
angle: angle,
|
|
);
|
|
}
|
|
|
|
class ParentSquare extends Square with HasGameRef {
|
|
ParentSquare(Vector2 position, Vector2 size) : super(position, size);
|
|
|
|
@override
|
|
void onMount() {
|
|
super.onMount();
|
|
createChildren();
|
|
}
|
|
|
|
void createChildren() {
|
|
// All positions here are in relation to the parent's position
|
|
final children = [
|
|
Square(Vector2(100, 100), Vector2(50, 50), angle: 2),
|
|
Square(Vector2(160, 100), Vector2(50, 50), angle: 3),
|
|
Square(Vector2(170, 150), Vector2(50, 50), angle: 4),
|
|
Square(Vector2(70, 200), Vector2(50, 50), angle: 5),
|
|
];
|
|
|
|
children.forEach((c) => addChild(c, gameRef: gameRef));
|
|
}
|
|
}
|
|
|
|
class Composability extends BaseGame with TapDetector {
|
|
late ParentSquare _parent;
|
|
|
|
@override
|
|
bool debugMode = true;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
_parent = ParentSquare(Vector2.all(200), Vector2.all(300))
|
|
..anchor = Anchor.center;
|
|
add(_parent);
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(dt);
|
|
_parent.angle += dt;
|
|
}
|
|
|
|
@override
|
|
void onTap() {
|
|
super.onTap();
|
|
_parent.scale = Vector2.all(2.0);
|
|
}
|
|
}
|