feat: adjusted SpriteAnimationComponent

pull/229/head
alestiago 3 years ago
parent a336ae81b0
commit 71a363b61a

@ -6,9 +6,6 @@ import 'package:flame_forge2d/flame_forge2d.dart' hide Timer;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
// TODO(alestiago): Make this global.
const _kImageToFlameRatio = 10.0;
/// {@template chrome_dino} /// {@template chrome_dino}
/// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it /// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it
/// back out. /// back out.
@ -51,7 +48,7 @@ class ChromeDino extends BodyComponent with InitialPosition {
repeat: true, repeat: true,
), ),
_ChromeDinoMouthSprite(), _ChromeDinoMouthSprite(),
// _ChromeDinoHeadSprite(), _ChromeDinoHeadSprite(),
], ],
); );
} }
@ -121,7 +118,7 @@ class ChromeDino extends BodyComponent with InitialPosition {
class _ChromeDinoAnchor extends JointAnchor { class _ChromeDinoAnchor extends JointAnchor {
/// {@macro flipper_anchor} /// {@macro flipper_anchor}
_ChromeDinoAnchor() { _ChromeDinoAnchor() {
initialPosition = Vector2(ChromeDino.size.x / 2, 0); initialPosition = Vector2(9, 0);
} }
} }
@ -168,17 +165,22 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
Assets.images.chromeDino.mouth.keyName, Assets.images.chromeDino.mouth.keyName,
); );
size = Vector2(25, 20);
position = Vector2(0, -2); position = Vector2(0, -2);
anchor = Anchor.center; anchor = Anchor.center;
const amountPerRow = 10; const amountPerRow = 11;
const amountPerColumn = 10; const amountPerColumn = 9;
final textureSize = Vector2(
image.width / amountPerRow,
image.height / amountPerColumn,
);
size = textureSize / 10;
final data = SpriteAnimationData.sequenced( final data = SpriteAnimationData.sequenced(
amount: amountPerColumn * amountPerRow, amount: (amountPerColumn * amountPerRow) - 1,
amountPerRow: amountPerRow, amountPerRow: amountPerRow,
stepTime: 0.10, stepTime: 0.1,
textureSize: size * _kImageToFlameRatio, textureSize: textureSize,
); );
animation = SpriteAnimation.fromFrameData(image, data); animation = SpriteAnimation.fromFrameData(image, data);
} }
@ -192,17 +194,22 @@ class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef {
Assets.images.chromeDino.head.keyName, Assets.images.chromeDino.head.keyName,
); );
size = Vector2(25, 20);
position = Vector2(0, -2); position = Vector2(0, -2);
anchor = Anchor.center; anchor = Anchor.center;
const amountPerRow = 10; const amountPerRow = 11;
const amountPerColumn = 10; const amountPerColumn = 9;
final textureSize = Vector2(
image.width / amountPerRow,
image.height / amountPerColumn,
);
size = textureSize / 10;
final data = SpriteAnimationData.sequenced( final data = SpriteAnimationData.sequenced(
amount: amountPerColumn * amountPerRow, amount: (amountPerColumn * amountPerRow) - 1,
amountPerRow: amountPerRow, amountPerRow: amountPerRow,
stepTime: 1, stepTime: 0.1,
textureSize: size * _kImageToFlameRatio, textureSize: textureSize,
); );
animation = SpriteAnimation.fromFrameData(image, data); animation = SpriteAnimation.fromFrameData(image, data);
} }

Loading…
Cancel
Save