Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making SpriteComponent and SpriteAnimationComponent follow the same standard for empty constructors #620

Merged
merged 2 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions doc/examples/animations/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
5 changes: 3 additions & 2 deletions doc/examples/aseprite/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions doc/examples/render_flip/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 8 additions & 7 deletions doc/examples/spritesheet/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/components/sprite_animation_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ 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,
}) : assert(animation != null) {
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.
Expand Down
1 change: 1 addition & 0 deletions lib/components/sprite_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down