Skip to content

Commit

Permalink
docs(readme): update player implementation (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardodalarme authored Aug 28, 2024
1 parent 64170f2 commit 869fbd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MyLeapGame extends LeapGame with HasTappables, HasKeyboardHandlerComponent
Future<void> onLoad() async {
await super.onLoad();
// "map.tmx" should be a Tiled map the meets the Leap requirements defined below
// "map.tmx" should be a Tiled map that meets the Leap requirements defined below
await loadWorldAndMap('map.tmx', 16);
setFixedViewportInTiles(32, 16);
Expand Down Expand Up @@ -148,28 +148,28 @@ it dies.

Characters are typically rendered visually as a `SpriteAnimation`, however most
likely there is a different animation for different states of the character.
That's where `CharacterAnimation` comes in.
That's where `AnchoredAnimationGroup` comes in.

A `CharacterAnimation` is a specialized `SpriteAnimationGroupComponent`, so you
A `AnchoredAnimationGroup` is a specialized `SpriteAnimationGroupComponent`, so you
can set all the animations as map on the component and then update the current
animation with the key in the map for the correct animation.

Typically you want to make use of this by making a subclass of
`CharacterAnimation` so all the logic relevant to picking the current animation
`AnchoredAnimationGroup` so all the logic relevant to picking the current animation
is self contained.

For example:

```dart
class Player extends Character {
class Player extends JumperCharacter with HasAnimationGroup {
Player() {
characterAnimation = PlayerAnimation();
animationGroup = PlayerAnimation();
}
}
enum _AnimationState { walk, jump }
class PlayerAnimation extends CharacterAnimation<_AnimationState, Player> {
class PlayerAnimation extends AnchoredAnimationGroup<_AnimationState, Player> {
@override
Future<void> onLoad() async {
animations = {
Expand All @@ -191,20 +191,21 @@ class PlayerAnimation extends CharacterAnimation<_AnimationState, Player> {
}
```

`CharacterAnimation` also automatically handles positioning the animation to be
centered on the parent's hitbox. The positioning can be changed with the
`AnchoredAnimationGroup` also automatically handles positioning the animation
to be centered on the parent's hitbox. The positioning can be changed with the
`hitboxAnchor` property.

`CharacterAnimation` must be added as child of a `Character` component, and
typically is set to the `characterAnimation` property as well.
`AnchoredAnimationGroup` must be added via the `HasAnimationGroup` mixin in a
`PhysicalEntity` component, and typically is set to the `animationGroup`
property as well.

##### Death animations

The recommended way to handle death animations is to set `removeOnDeath = true`
and `finishAnimationBeforeRemove = true`. You will also need to:

1. Have a `CharacterAnimation` set on the character, and make sure it sets the
`current` animation to whichever death animation you need.
1. Have a `AnchoredAnimationGroup` set on the character, and make sure it sets
the `current` animation to whichever death animation you need.
2. Make sure the death animation has `loop = false` so it doesn't play forever.
3. Make sure the rest of your game doesn't interact with it as if it is still
alive. The recommened approach for this is to add a custom `Status` to it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract interface class GroundTileHandler {
/// Implementers have full flexibility,
/// but generally want do one of the following:
/// 1. Modify properties of [tile], add tags
/// 2. Return a custom immplementation of [LeapMapGroundTile]
/// 2. Return a custom implementation of [LeapMapGroundTile]
/// 3. Create an additional PhysicalEntity with custom behavior at the same
/// location as the tile.
LeapMapGroundTile handleGroundTile(LeapMapGroundTile tile, LeapMap map);
Expand Down

0 comments on commit 869fbd7

Please sign in to comment.