mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 8b132d7c0b
			
		
	
	8b132d7c0b
	
	
	
		
			
			* 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
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/effects.dart';
 | |
| import 'package:flame/extensions.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/input.dart';
 | |
| import 'package:flame/palette.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| import '../../commons/square_component.dart';
 | |
| 
 | |
| class ScaleEffectExample extends FlameGame with TapDetector {
 | |
|   static const String description = '''
 | |
|     The `ScaleEffect` scales up the canvas before drawing the components and its
 | |
|     children.
 | |
|     In this example you can tap the screen and the component will scale up or down,
 | |
|     depending on its current state.
 | |
|   ''';
 | |
| 
 | |
|   late SquareComponent square;
 | |
|   bool grow = true;
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     await super.onLoad();
 | |
|     square = SquareComponent()
 | |
|       ..position.setValues(200, 200)
 | |
|       ..anchor = Anchor.center;
 | |
|     square.paint = BasicPalette.white.paint()..style = PaintingStyle.stroke;
 | |
|     final childSquare = SquareComponent(position: Vector2.all(70), size: 20);
 | |
| 
 | |
|     square.add(childSquare);
 | |
|     add(square);
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void onTap() {
 | |
|     final s = grow ? 3.0 : 1.0;
 | |
| 
 | |
|     grow = !grow;
 | |
|     square.add(
 | |
|       ScaleEffect(
 | |
|         scale: Vector2.all(s),
 | |
|         speed: 2.0,
 | |
|         curve: Curves.linear,
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| }
 |