mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	Add random to the Color and Paint extensions (#1081)
				
					
				
			* Add `randomColor` to the `Color` extension * Add flame rive package to monorepo (#1048) Add flame rive package to monorepo * Add random to PaintExtension * Update examples/pubspec.yaml Co-authored-by: Erick <erickzanardoo@gmail.com> Co-authored-by: Renan <6718144+renancaraujo@users.noreply.github.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
This commit is contained in:
		| @ -1,6 +1,5 @@ | ||||
| import 'dart:math'; | ||||
|  | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/input.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| @ -85,7 +84,7 @@ class Square extends PositionComponent with HasGameRef<RiveExampleGame> { | ||||
|   Square(Vector2 position) { | ||||
|     this.position.setFrom(position); | ||||
|     size.setValues(100, 100); | ||||
|     paint = _randomPaint(); | ||||
|     paint = PaintExtension.random(withAlpha: 0.9, base: 100); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
| @ -93,15 +92,4 @@ class Square extends PositionComponent with HasGameRef<RiveExampleGame> { | ||||
|     super.render(canvas); | ||||
|     canvas.drawRect(size.toRect(), paint); | ||||
|   } | ||||
|  | ||||
|   static Paint _randomPaint() { | ||||
|     final rng = Random(); | ||||
|     final color = Color.fromRGBO( | ||||
|       rng.nextInt(256), | ||||
|       rng.nextInt(256), | ||||
|       rng.nextInt(256), | ||||
|       0.9, | ||||
|     ); | ||||
|     return PaletteEntry(color).paint(); | ||||
|   } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Lukas Klingsbo
					Lukas Klingsbo