Skip to content

Instantly share code, notes, and snippets.

@spydon
Created June 20, 2022 09:19
Show Gist options
  • Save spydon/a0225cea7a7138f0ca695eb3240bfe8b to your computer and use it in GitHub Desktop.
Save spydon/a0225cea7a7138f0ca695eb3240bfe8b to your computer and use it in GitHub Desktop.
Heart by Agnel Selvan
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
GameWidget(
game: HeartEffect(),
),
);
}
class HeartEffect extends FlameGame {
@override
Future<void> onLoad() async {
add(
HeartIcon()
..add(
ScaleEffect.to(
Vector2.all(1.4),
InfiniteEffectController(
SequenceEffectController(
[
CurvedEffectController(0.4, Curves.bounceOut),
PauseEffectController(0.5, progress: 1),
ReverseCurvedEffectController(0.4, Curves.bounceIn)
],
),
),
),
),
);
}
}
class HeartIcon extends PositionComponent {
HeartIcon()
: super(
anchor: Anchor.center,
position: Vector2.all(100),
size: Vector2.all(60),
) {
shape = Path()
..moveTo(width * 0.5 * scale.x, height * 0.35 * scale.y)
..cubicTo(0.2 * width, height * 0.1, -0.25 * width, height * 0.6,
0.5 * width, height)
..moveTo(0.5 * width, height * 0.35)
..cubicTo(0.8 * width, height * 0.1, 1.25 * width, height * 0.6,
0.5 * width, height);
shape.close();
}
late final Path shape;
late final Paint paint = Paint()
..color = Colors.red
..style = PaintingStyle.fill
..strokeWidth = 0;
@override
void render(Canvas canvas) {
canvas.drawPath(shape, paint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment