mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-31 00:48:47 +08:00
* No setter for position and size * Use setter for position and size * Add onPositionUpdate and snapTo to Camera * Fix formatting * Fix size in test * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Better naming for internal position state * Anchor and angle defaults on effect test utils * No setter for position and size * Fix scale effect * Fix formatting Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
73 lines
1.8 KiB
Dart
73 lines
1.8 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/palette.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
final _regular = TextConfig(color: BasicPalette.white.color);
|
|
final _tiny = _regular.withFontSize(12.0);
|
|
|
|
final _white = Paint()
|
|
..color = BasicPalette.white.color
|
|
..style = PaintingStyle.stroke;
|
|
|
|
class MyTextBox extends TextBoxComponent {
|
|
MyTextBox(String text)
|
|
: super(
|
|
text,
|
|
config: _tiny,
|
|
boxConfig: TextBoxConfig(
|
|
timePerChar: 0.05,
|
|
growingBox: true,
|
|
margins: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
|
|
),
|
|
);
|
|
|
|
@override
|
|
void drawBackground(Canvas c) {
|
|
final rect = Rect.fromLTWH(0, 0, width, height);
|
|
c.drawRect(rect, Paint()..color = const Color(0xFFFF00FF));
|
|
final margin = boxConfig.margins;
|
|
final innerRect = Rect.fromLTWH(
|
|
margin.left,
|
|
margin.top,
|
|
width - margin.horizontal,
|
|
height - margin.vertical,
|
|
);
|
|
c.drawRect(innerRect, _white);
|
|
}
|
|
}
|
|
|
|
class TextGame extends BaseGame {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
add(
|
|
TextComponent('Hello, Flame', config: _regular)
|
|
..anchor = Anchor.topCenter
|
|
..x = size.x / 2
|
|
..y = 32.0,
|
|
);
|
|
|
|
add(
|
|
TextComponent('center', config: _tiny)
|
|
..anchor = Anchor.center
|
|
..position.setFrom(size / 2),
|
|
);
|
|
|
|
add(
|
|
TextComponent('bottomRight', config: _tiny)
|
|
..anchor = Anchor.bottomRight
|
|
..position.setFrom(size),
|
|
);
|
|
|
|
add(
|
|
MyTextBox(
|
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ligula eu lectus lobortis condimentum.',
|
|
)
|
|
..anchor = Anchor.bottomLeft
|
|
..y = size.y,
|
|
);
|
|
}
|
|
}
|