mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 3cb23ef530
			
		
	
	3cb23ef530
	
	
	
		
			
			* `TextPaint` to use `TextStyle` instead of `TextPaintConfig` * Update packages/flame/lib/src/text.dart Co-authored-by: Pasha Stetsenko <stpasha@google.com> * Removed BaseTextConfig and TextPaintConfig * Update text docs * Apply suggestions from code review Co-authored-by: Erick <erickzanardoo@gmail.com> * Remove generics * Update TextBoxExample * Update text examples variable names * Fix TextPaint in collision_detection example Co-authored-by: Pasha Stetsenko <stpasha@google.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
		
			
				
	
	
		
			78 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:ui' hide TextStyle;
 | |
| 
 | |
| import 'package:flame/components.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| class LogoCompomnent extends SpriteComponent with HasGameRef<DebugGame> {
 | |
|   static const int speed = 150;
 | |
| 
 | |
|   int xDirection = 1;
 | |
|   int yDirection = 1;
 | |
| 
 | |
|   LogoCompomnent(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;
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| class DebugGame extends FlameGame with FPSCounter {
 | |
|   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 = LogoCompomnent(flameLogo);
 | |
|     flame1.x = 100;
 | |
|     flame1.y = 400;
 | |
| 
 | |
|     final flame2 = LogoCompomnent(flameLogo);
 | |
|     flame2.x = 100;
 | |
|     flame2.y = 400;
 | |
|     flame2.yDirection = -1;
 | |
| 
 | |
|     final flame3 = LogoCompomnent(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));
 | |
|     }
 | |
|   }
 | |
| }
 |