Skip to content

Instantly share code, notes, and snippets.

@vbalagovic
Created March 3, 2023 14:21
Show Gist options
  • Save vbalagovic/3dfe12daaaa30009ccaff21cfb09bf9f to your computer and use it in GitHub Desktop.
Save vbalagovic/3dfe12daaaa30009ccaff21cfb09bf9f to your computer and use it in GitHub Desktop.
enum PlayerState { regular, duck, left, right, jump, hit, shoot }
...
@override
Future<void> onLoad() async {
await super.onLoad();
await _loadCharacterSprites();
position = Vector2(size.x, gameRef.size.y - 10);
}
...
Future<void> _loadCharacterSprites() async {
final regular = await gameRef.loadSpriteAnimation(
'spritesheet.png',
SpriteAnimationData.sequenced(
amount: 7,
textureSize: Vector2(63.4, 130.0),
stepTime: 0.15,
loop: true,
));
final right = await gameRef.loadSpriteAnimation(
'left.png',
SpriteAnimationData.sequenced(
amount: 5,
textureSize: Vector2(63.4, 130.0),
stepTime: 0.20,
loop: true,
));
final left = await gameRef.loadSpriteAnimation(
'right.png',
SpriteAnimationData.sequenced(
amount: 5,
textureSize: Vector2(63.4, 130.0),
stepTime: 0.20,
loop: true,
));
final jump = await gameRef.loadSpriteAnimation(
'jump.png',
SpriteAnimationData.sequenced(
amount: 3,
textureSize: Vector2(70.4, 130.0),
stepTime: .2,
loop: false,
));
final hit = await gameRef.loadSpriteAnimation(
'hit.png',
SpriteAnimationData.sequenced(
amount: 3,
textureSize: Vector2(73.4, 110.0),
stepTime: 0.20,
loop: false,
));
final shoot = await gameRef.loadSpriteAnimation(
'shoot.png',
SpriteAnimationData.sequenced(
amount: 3,
textureSize: Vector2(90.4, 110.0),
stepTime: 0.20,
loop: false,
));
final player = SpriteAnimationGroupComponent<PlayerState>(animations: {
PlayerState.regular: regular,
PlayerState.left: left,
PlayerState.right: right,
PlayerState.jump: jump,
PlayerState.hit: hit,
PlayerState.shoot: shoot,
//PlayerState.duck: duck,
}, current: PlayerState.regular);
animations = player.animations;
current = PlayerState.regular;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment