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:
		
							
								
								
									
										82
									
								
								examples/lib/stories/components/debug_example.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								examples/lib/stories/components/debug_example.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,82 @@ | ||||
| import 'dart:ui' hide TextStyle; | ||||
|  | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| class DebugExample extends FlameGame with FPSCounter { | ||||
|   static const String description = ''' | ||||
|     In this example we show what you will see when setting `debugMode = true` on | ||||
|     your game. It is a non-interactive example. | ||||
|   '''; | ||||
|  | ||||
|   static final fpsTextPaint = TextPaint( | ||||
|     style: const TextStyle(color: Color(0xFFFFFFFF)), | ||||
|   ); | ||||
|  | ||||
|   @override | ||||
|   bool debugMode = true; | ||||
|  | ||||
|   @override | ||||
|   Future<void> onLoad() async { | ||||
|     await super.onLoad(); | ||||
|     final flameLogo = await loadSprite('flame.png'); | ||||
|  | ||||
|     final flame1 = LogoComponent(flameLogo); | ||||
|     flame1.x = 100; | ||||
|     flame1.y = 400; | ||||
|  | ||||
|     final flame2 = LogoComponent(flameLogo); | ||||
|     flame2.x = 100; | ||||
|     flame2.y = 400; | ||||
|     flame2.yDirection = -1; | ||||
|  | ||||
|     final flame3 = LogoComponent(flameLogo); | ||||
|     flame3.x = 100; | ||||
|     flame3.y = 400; | ||||
|     flame3.xDirection = -1; | ||||
|  | ||||
|     add(flame1); | ||||
|     add(flame2); | ||||
|     add(flame3); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void render(Canvas canvas) { | ||||
|     super.render(canvas); | ||||
|  | ||||
|     if (debugMode) { | ||||
|       fpsTextPaint.render(canvas, fps(120).toString(), Vector2(0, 50)); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| class LogoComponent extends SpriteComponent with HasGameRef<DebugExample> { | ||||
|   static const int speed = 150; | ||||
|  | ||||
|   int xDirection = 1; | ||||
|   int yDirection = 1; | ||||
|  | ||||
|   LogoComponent(Sprite sprite) : super(sprite: sprite, size: sprite.srcSize); | ||||
|  | ||||
|   @override | ||||
|   void update(double dt) { | ||||
|     super.update(dt); | ||||
|  | ||||
|     x += xDirection * speed * dt; | ||||
|  | ||||
|     final rect = toRect(); | ||||
|  | ||||
|     if ((x <= 0 && xDirection == -1) || | ||||
|         (rect.right >= gameRef.size.x && xDirection == 1)) { | ||||
|       xDirection = xDirection * -1; | ||||
|     } | ||||
|  | ||||
|     y += yDirection * speed * dt; | ||||
|  | ||||
|     if ((y <= 0 && yDirection == -1) || | ||||
|         (rect.bottom >= gameRef.size.y && yDirection == 1)) { | ||||
|       yDirection = yDirection * -1; | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Lukas Klingsbo
					Lukas Klingsbo