Files
Lukas Klingsbo cd7a0bbb65 ShapeComponent and Hitbox to take transform of parents full ancestor tree into consideration (#1076)
* `ShapeComponent` changes size, position and angle of underlying Shape

* Added description to ShapeComponent

* Fix test

* Update packages/flame/lib/src/components/shape_component.dart

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Add absoluteScale and absoluteAngle to PositionComponent

* Refactor ShapeComponent

* Should be scaled by total scale, not scaled size

* Premature optimization for creation for objects in Polygon

* Use path for default Polygon constructor

* Do not sync component and hitbox shape

* Fix analyze issue

* Add example for flipping with collision detection

* Don't use absoluteScale

* Fix examples

* Fix examples

* Doesn't need super.render

* Fix Circle dartdoc

* Update changelog

* Update names of vertices caches in Polygon

* Update text docs

* Revert "Update text docs"

This reverts commit 73a68a465d76eb0eb50bb3753e57b2f4e3b5a7f4.

* Fix examples

* ShapeComponents docs

* Move example games to the top

* Fix dartdoc comment about polygon vertex relation

* Fix order of polygon vertices in dartdoc

* Fix anchor for PolygonComponent.fromPoints

* Add test with ancestors

* Update doc/components.md

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Update doc/components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Rename example classes

* Fix linting issues in examples

* Don't use px

* Use isTrue and isFalse

* Update doc/components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Fixed comments on PR

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2021-11-13 16:00:24 +01:00

80 lines
1.8 KiB
Dart

import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flame_rive/flame_rive.dart';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final game = RiveExampleGame();
@override
Widget build(BuildContext context) {
return GameWidget(
game: game,
);
}
}
class RiveExampleGame extends FlameGame with HasTappableComponents {
@override
Color backgroundColor() {
return const Color(0xFFFFFFFF);
}
@override
Future<void>? onLoad() async {
await super.onLoad();
final skillsArtboard =
await loadArtboard(RiveFile.asset('assets/skills.riv'));
add(SkillsAnimationComponent(skillsArtboard));
}
}
class SkillsAnimationComponent extends RiveComponent with Tappable {
SkillsAnimationComponent(Artboard artboard)
: super(
artboard: artboard,
size: Vector2.all(550),
);
SMIInput<double>? _levelInput;
@override
Future<void>? onLoad() {
final controller = StateMachineController.fromArtboard(
artboard,
"Designer's Test",
);
if (controller != null) {
artboard.addController(controller);
_levelInput = controller.findInput<double>('Level');
_levelInput?.value = 0;
}
return super.onLoad();
}
@override
bool onTapDown(TapDownInfo info) {
final levelInput = _levelInput;
if (levelInput == null) {
return false;
}
levelInput.value = (levelInput.value + 1) % 3;
return true;
}
}