mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 01:18:38 +08:00
* `TextPaint` to use `TextStyle` instead of `TextPaintConfig` * Update packages/flame/lib/src/text.dart Co-authored-by: Pasha Stetsenko <stpasha@google.com> * Removed BaseTextConfig and TextPaintConfig * Update text docs * Apply suggestions from code review Co-authored-by: Erick <erickzanardoo@gmail.com> * Remove generics * Update TextBoxExample * Update text examples variable names * Fix TextPaint in collision_detection example Co-authored-by: Pasha Stetsenko <stpasha@google.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
57 lines
1.5 KiB
Dart
57 lines
1.5 KiB
Dart
import 'package:flame/extensions.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame_oxygen/flame_oxygen.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../component/timer_component.dart';
|
|
import '../component/velocity_component.dart';
|
|
import '../main.dart';
|
|
|
|
class MoveSystem extends System with UpdateSystem, GameRef<ExampleGame> {
|
|
Query? _query;
|
|
|
|
@override
|
|
void init() {
|
|
_query = createQuery([
|
|
Has<PositionComponent>(),
|
|
Has<VelocityComponent>(),
|
|
]);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_query = null;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void update(double delta) {
|
|
for (final entity in _query?.entities ?? <Entity>[]) {
|
|
final velocity = entity.get<VelocityComponent>()!.velocity;
|
|
final size = entity.get<SizeComponent>()!.size;
|
|
final position = entity.get<PositionComponent>()!.position
|
|
..add(velocity * delta);
|
|
|
|
final screenSize = Vector2.zero() & game!.size;
|
|
if (!screenSize.containsPoint(position) ||
|
|
!screenSize.containsPoint(position + size)) {
|
|
velocity.setFrom(-velocity);
|
|
|
|
game!.createEntity(
|
|
name: '${entity.name} says',
|
|
position: position + size / 2,
|
|
size: Vector2.zero(),
|
|
anchor: Anchor.topCenter,
|
|
)
|
|
..add<TextComponent, TextInit>(
|
|
TextInit(
|
|
'Kawabunga',
|
|
style: const TextStyle(color: Colors.blue, fontSize: 12),
|
|
),
|
|
)
|
|
..add<TimerComponent, double>(3);
|
|
}
|
|
}
|
|
}
|
|
}
|