mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	Unify examples structure (#1118)
* 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
This commit is contained in:
		
							
								
								
									
										55
									
								
								examples/lib/stories/utils/timer_example.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								examples/lib/stories/utils/timer_example.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/input.dart'; | ||||
| import 'package:flame/timer.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| class TimerExample extends FlameGame with TapDetector { | ||||
|   static const String description = ''' | ||||
|     This example shows how to use the `Timer`.\n\n | ||||
|     Tap down to start the countdown timer, it will then count to 5 and then stop | ||||
|     until you tap the canvas again and it restarts. | ||||
|   '''; | ||||
|  | ||||
|   final TextPaint textConfig = TextPaint( | ||||
|     style: const TextStyle(color: Colors.white, fontSize: 20), | ||||
|   ); | ||||
|   late Timer countdown; | ||||
|   late Timer interval; | ||||
|  | ||||
|   int elapsedSecs = 0; | ||||
|  | ||||
|   @override | ||||
|   Future<void> onLoad() async { | ||||
|     await super.onLoad(); | ||||
|     countdown = Timer(5); | ||||
|     interval = Timer( | ||||
|       1, | ||||
|       onTick: () => elapsedSecs += 1, | ||||
|       repeat: true, | ||||
|     ); | ||||
|     interval.start(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void onTapDown(_) { | ||||
|     countdown.start(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void update(double dt) { | ||||
|     super.update(dt); | ||||
|     countdown.update(dt); | ||||
|     interval.update(dt); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void render(Canvas canvas) { | ||||
|     super.render(canvas); | ||||
|     textConfig.render( | ||||
|       canvas, | ||||
|       'Countdown: ${countdown.current.toStringAsPrecision(3)}', | ||||
|       Vector2(30, 100), | ||||
|     ); | ||||
|     textConfig.render(canvas, 'Elapsed time: $elapsedSecs', Vector2(30, 130)); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Lukas Klingsbo
					Lukas Klingsbo