mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
* Animations, CameraAndViewport, CollisionDetection and Components unified * Added descriptions to effects * Rename input games * Unify input stories * Add info to parallax section * Added descriptions to the rendering examples * Add descriptions to the sprites directory * Fix utils and rendering section * Add descriptions to the widgets section * Delete directory that rebase brought back * Unify game names * Added some styleguide docs for examples * Fix analyze issues * All files should have _example as suffix * Made the FollowComponentExample a bit easier to understand * Change priority of ember
77 lines
1.9 KiB
Dart
77 lines
1.9 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flame/effects.dart';
|
|
import 'package:flame/extensions.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../commons/square_component.dart';
|
|
|
|
final green = Paint()..color = const Color(0xAA338833);
|
|
final red = Paint()..color = const Color(0xAA883333);
|
|
final orange = Paint()..color = const Color(0xAABB6633);
|
|
|
|
class InfiniteEffectExample extends FlameGame with TapDetector {
|
|
static const String description = '''
|
|
In this example we show how effects can run in infinity with the
|
|
`isInfinite: true` argument. Click on the screen to start the effects.
|
|
''';
|
|
|
|
late SquareComponent greenSquare;
|
|
late SquareComponent redSquare;
|
|
late SquareComponent orangeSquare;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
|
|
SquareComponent makeSquare(Paint paint) {
|
|
return SquareComponent(position: Vector2.all(100), paint: paint);
|
|
}
|
|
|
|
add(greenSquare = makeSquare(green));
|
|
add(redSquare = makeSquare(red));
|
|
add(orangeSquare = makeSquare(orange));
|
|
}
|
|
|
|
@override
|
|
void onTapUp(TapUpInfo info) {
|
|
final p = info.eventPosition.game;
|
|
|
|
greenSquare.clearEffects();
|
|
redSquare.clearEffects();
|
|
orangeSquare.clearEffects();
|
|
|
|
greenSquare.add(
|
|
MoveEffect(
|
|
path: [p],
|
|
speed: 250.0,
|
|
curve: Curves.bounceInOut,
|
|
isInfinite: true,
|
|
isAlternating: true,
|
|
),
|
|
);
|
|
|
|
redSquare.add(
|
|
SizeEffect(
|
|
size: p,
|
|
speed: 250.0,
|
|
curve: Curves.easeInCubic,
|
|
isInfinite: true,
|
|
isAlternating: true,
|
|
),
|
|
);
|
|
|
|
orangeSquare.add(
|
|
RotateEffect(
|
|
angle: (p.x + p.y) % (2 * pi),
|
|
speed: 1.0, // Radians per second
|
|
curve: Curves.easeInOut,
|
|
isInfinite: true,
|
|
isAlternating: true,
|
|
),
|
|
);
|
|
}
|
|
}
|