mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	* some initial refactoring * Fixing examples and joystick component * Fixing examples * Addressing comments from PR * Fixing tutorials * Updating docs * Fixing tests * PR followup * A big follow up * linting * doc nit * Changelog and fix tutorial * Addressing comments * Fixing BaseGame project and scale offset methods * Formatting * doc suggestions * Update packages/flame/lib/src/gestures/events.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Hopefully, the last follow up * Linting and adding dart-code-metrics again * fixing tutorial Co-authored-by: Luan Nico <luanpotter27@gmail.com>
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:flame/effects.dart';
 | 
						|
import 'package:flame/extensions.dart';
 | 
						|
import 'package:flame/game.dart';
 | 
						|
import 'package:flame/gestures.dart';
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
 | 
						|
import '../../commons/square_component.dart';
 | 
						|
 | 
						|
final green = Paint()..color = const Color(0xAA338833);
 | 
						|
 | 
						|
class SequenceEffectGame extends BaseGame with TapDetector {
 | 
						|
  late SquareComponent greenSquare;
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<void> onLoad() async {
 | 
						|
    greenSquare = SquareComponent()
 | 
						|
      ..paint = green
 | 
						|
      ..position.setValues(100, 100);
 | 
						|
    add(greenSquare);
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  void onTapUp(TapUpInfo event) {
 | 
						|
    final currentTap = event.eventPosition.game;
 | 
						|
    greenSquare.clearEffects();
 | 
						|
 | 
						|
    final move1 = MoveEffect(
 | 
						|
      path: [currentTap],
 | 
						|
      speed: 250.0,
 | 
						|
      curve: Curves.bounceInOut,
 | 
						|
      isAlternating: true,
 | 
						|
    );
 | 
						|
 | 
						|
    final move2 = MoveEffect(
 | 
						|
      path: [
 | 
						|
        currentTap + Vector2(0, 50),
 | 
						|
        currentTap + Vector2(-50, -50),
 | 
						|
        currentTap + Vector2(50, 0),
 | 
						|
      ],
 | 
						|
      speed: 150.0,
 | 
						|
      curve: Curves.easeIn,
 | 
						|
    );
 | 
						|
 | 
						|
    final scale = ScaleEffect(
 | 
						|
      size: currentTap,
 | 
						|
      speed: 100.0,
 | 
						|
      curve: Curves.easeInCubic,
 | 
						|
    );
 | 
						|
 | 
						|
    final rotate = RotateEffect(
 | 
						|
      angle: currentTap.angleTo(Vector2.all(100)),
 | 
						|
      duration: 0.8,
 | 
						|
      curve: Curves.decelerate,
 | 
						|
    );
 | 
						|
 | 
						|
    final combination = CombinedEffect(
 | 
						|
      effects: [move2, rotate],
 | 
						|
      isAlternating: true,
 | 
						|
      onComplete: () => print('combination complete'),
 | 
						|
    );
 | 
						|
 | 
						|
    final sequence = SequenceEffect(
 | 
						|
      effects: [move1, scale, combination],
 | 
						|
      isAlternating: true,
 | 
						|
    );
 | 
						|
    sequence.onComplete = () => print('sequence complete');
 | 
						|
    greenSquare.addEffect(sequence);
 | 
						|
  }
 | 
						|
}
 |