mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Possibility to initialize all PositionComponents from onLoad (#1113)
* Fix ParallaxComponent constructor * Fix sizing bug parallax_component * Unify TextComponent and TextBoxComponent * Fix tests * Update PositionComponent docs * Add changelog entry * Apply suggestions from code review Co-authored-by: Erick <erickzanardoo@gmail.com> * Fix analyze issue * Apply suggestions from code review Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Fix line length in components.md Co-authored-by: Erick <erickzanardoo@gmail.com> Co-authored-by: Luan Nico <luanpotter27@gmail.com>
This commit is contained in:
@ -105,11 +105,11 @@ class JoystickAdvancedGame extends FlameGame with HasDraggables, HasTappables {
|
||||
style: TextStyle(color: BasicPalette.white.color),
|
||||
);
|
||||
speedText = TextComponent(
|
||||
'Speed: 0',
|
||||
text: 'Speed: 0',
|
||||
textRenderer: _regular,
|
||||
)..isHud = true;
|
||||
directionText = TextComponent(
|
||||
'Direction: idle',
|
||||
text: 'Direction: idle',
|
||||
textRenderer: _regular,
|
||||
)..isHud = true;
|
||||
|
||||
|
||||
@ -20,8 +20,8 @@ class AdvancedParallaxGame extends FlameGame {
|
||||
velocityMultiplier: Vector2(e.value, 1.0),
|
||||
),
|
||||
);
|
||||
final parallax = ParallaxComponent.fromParallax(
|
||||
Parallax(
|
||||
final parallax = ParallaxComponent(
|
||||
parallax: Parallax(
|
||||
await Future.wait(layers),
|
||||
baseVelocity: Vector2(20, 0),
|
||||
),
|
||||
|
||||
@ -39,7 +39,7 @@ class AnimationParallaxGame extends FlameGame {
|
||||
baseVelocity: Vector2(20, 0),
|
||||
);
|
||||
|
||||
final parallaxComponent = ParallaxComponent.fromParallax(parallax);
|
||||
final parallaxComponent = ParallaxComponent(parallax: parallax);
|
||||
add(parallaxComponent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +65,6 @@ class SandBoxLayerParallaxGame extends FlameGame {
|
||||
baseVelocity: Vector2(20, 0),
|
||||
);
|
||||
|
||||
add(ParallaxComponent.fromParallax(parallax));
|
||||
add(ParallaxComponent(parallax: parallax));
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ final _shaded = TextPaint(
|
||||
class MyTextBox extends TextBoxComponent {
|
||||
MyTextBox(String text)
|
||||
: super(
|
||||
text,
|
||||
text: text,
|
||||
textRenderer: _box,
|
||||
boxConfig: TextBoxConfig(
|
||||
maxWidth: 400,
|
||||
@ -52,26 +52,26 @@ class TextGame extends FlameGame {
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
add(
|
||||
TextComponent('Hello, Flame', textRenderer: _regular)
|
||||
TextComponent(text: 'Hello, Flame', textRenderer: _regular)
|
||||
..anchor = Anchor.topCenter
|
||||
..x = size.x / 2
|
||||
..y = 32.0,
|
||||
);
|
||||
|
||||
add(
|
||||
TextComponent('Text with shade', textRenderer: _shaded)
|
||||
TextComponent(text: 'Text with shade', textRenderer: _shaded)
|
||||
..anchor = Anchor.topRight
|
||||
..position = size - Vector2.all(100),
|
||||
);
|
||||
|
||||
add(
|
||||
TextComponent('center', textRenderer: _tiny)
|
||||
TextComponent(text: 'center', textRenderer: _tiny)
|
||||
..anchor = Anchor.center
|
||||
..position.setFrom(size / 2),
|
||||
);
|
||||
|
||||
add(
|
||||
TextComponent('bottomRight', textRenderer: _tiny)
|
||||
TextComponent(text: 'bottomRight', textRenderer: _tiny)
|
||||
..anchor = Anchor.bottomRight
|
||||
..position.setFrom(size),
|
||||
);
|
||||
|
||||
@ -39,8 +39,8 @@ class SpritebatchGame extends FlameGame {
|
||||
}
|
||||
|
||||
add(
|
||||
SpriteBatchComponent.fromSpriteBatch(
|
||||
spriteBatch,
|
||||
SpriteBatchComponent(
|
||||
spriteBatch: spriteBatch,
|
||||
blendMode: BlendMode.srcOver,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user