mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Making SpriteComponent and SpriteAnimationComponent follow the same standard for empty constructors (#620)
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
- Add tests for `Timer` and fix a bug where `progress` was not reported correctly
|
||||
- Updated the `widgets.md` documentation
|
||||
- Removing methods `initialDimensions` and `removeGestureRecognizer` to avoid confusion
|
||||
- Adding standard for `SpriteComponent` and `SpriteAnimationComponent` constructors
|
||||
|
||||
## 1.0.0-rc5
|
||||
- Option for overlays to be already visible on the GameWidget
|
||||
|
||||
@ -39,11 +39,13 @@ class MyGame extends BaseGame with TapDetector {
|
||||
);
|
||||
|
||||
final spriteSize = Vector2.all(100.0);
|
||||
final animationComponent2 = SpriteAnimationComponent(spriteSize, animation);
|
||||
final animationComponent2 =
|
||||
SpriteAnimationComponent.fromSpriteAnimation(spriteSize, animation);
|
||||
animationComponent2.x = size.x / 2 - spriteSize.x;
|
||||
animationComponent2.y = spriteSize.y;
|
||||
|
||||
final reversedAnimationComponent = SpriteAnimationComponent(
|
||||
final reversedAnimationComponent =
|
||||
SpriteAnimationComponent.fromSpriteAnimation(
|
||||
spriteSize,
|
||||
animation.reversed(),
|
||||
);
|
||||
|
||||
@ -22,8 +22,9 @@ class MyGame extends BaseGame {
|
||||
jsonData,
|
||||
);
|
||||
final spriteSize = Vector2.all(200);
|
||||
final animationComponent = SpriteAnimationComponent(spriteSize, animation)
|
||||
..position = size / 2 - Vector2.all(100);
|
||||
final animationComponent =
|
||||
SpriteAnimationComponent.fromSpriteAnimation(spriteSize, animation)
|
||||
..position = size / 2 - Vector2.all(100);
|
||||
|
||||
add(animationComponent);
|
||||
}
|
||||
|
||||
@ -36,8 +36,10 @@ class MyGame extends BaseGame {
|
||||
}
|
||||
|
||||
SpriteAnimationComponent buildAnimationComponent(Image image) {
|
||||
final ac =
|
||||
SpriteAnimationComponent(Vector2.all(100), buildAnimation(image));
|
||||
final ac = SpriteAnimationComponent.fromSpriteAnimation(
|
||||
Vector2.all(100),
|
||||
buildAnimation(image),
|
||||
);
|
||||
ac.x = size.x / 2 - ac.x / 2;
|
||||
return ac;
|
||||
}
|
||||
|
||||
@ -29,14 +29,15 @@ class MyGame extends BaseGame {
|
||||
spriteSheet.createAnimation(row: 1, stepTime: 0.1, to: 7);
|
||||
final spriteSize = Vector2(80.0, 90.0);
|
||||
|
||||
final vampireComponent =
|
||||
SpriteAnimationComponent(spriteSize, vampireAnimation)
|
||||
..x = 150
|
||||
..y = 100;
|
||||
|
||||
final ghostComponent = SpriteAnimationComponent(spriteSize, ghostAnimation)
|
||||
final vampireComponent = SpriteAnimationComponent.fromSpriteAnimation(
|
||||
spriteSize, vampireAnimation)
|
||||
..x = 150
|
||||
..y = 220;
|
||||
..y = 100;
|
||||
|
||||
final ghostComponent =
|
||||
SpriteAnimationComponent.fromSpriteAnimation(spriteSize, ghostAnimation)
|
||||
..x = 150
|
||||
..y = 220;
|
||||
|
||||
add(vampireComponent);
|
||||
add(ghostComponent);
|
||||
|
||||
@ -11,10 +11,13 @@ class SpriteAnimationComponent extends PositionComponent {
|
||||
Paint overridePaint;
|
||||
bool removeOnFinish = false;
|
||||
|
||||
/// Creates a component with an empty animation which can be set later
|
||||
SpriteAnimationComponent();
|
||||
|
||||
/// Creates an [SpriteAnimationComponent] from an [animation] and a [size]
|
||||
///
|
||||
/// Optionally [removeOnFinish] can be set to true to have this component be auto removed from the [BaseGame] when the animation is finished.
|
||||
SpriteAnimationComponent(
|
||||
SpriteAnimationComponent.fromSpriteAnimation(
|
||||
Vector2 size,
|
||||
this.animation, {
|
||||
this.removeOnFinish = false,
|
||||
@ -22,9 +25,6 @@ class SpriteAnimationComponent extends PositionComponent {
|
||||
super.size.setFrom(size);
|
||||
}
|
||||
|
||||
/// Creates a component with an empty animation which can be set later
|
||||
SpriteAnimationComponent.empty();
|
||||
|
||||
/// Creates a SpriteAnimationComponent from a [size], an [image] and [data]. Check [SpriteAnimationData] for more info on the available options.
|
||||
///
|
||||
/// Optionally [removeOnFinish] can be set to true to have this component be auto removed from the [BaseGame] when the animation is finished.
|
||||
|
||||
@ -21,6 +21,7 @@ class SpriteComponent extends PositionComponent {
|
||||
/// If not provided the default is full white (no tint).
|
||||
Paint overridePaint;
|
||||
|
||||
/// Creates a component with an empty sprite which can be set later
|
||||
SpriteComponent();
|
||||
|
||||
SpriteComponent.fromImage(Vector2 size, Image image)
|
||||
|
||||
Reference in New Issue
Block a user