mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +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,11 +1,9 @@
|
||||
import 'dart:math';
|
||||
import 'dart:ui';
|
||||
|
||||
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';
|
||||
|
||||
const priorityInfo = '''
|
||||
On this example, click on the square to bring them to the front by changing the
|
||||
@ -18,7 +16,7 @@ class Square extends PositionComponent with HasGameRef<Priority>, Tappable {
|
||||
Square(Vector2 position) {
|
||||
this.position.setFrom(position);
|
||||
size.setValues(100, 100);
|
||||
paint = _randomPaint();
|
||||
paint = PaintExtension.random(withAlpha: 0.9, base: 100);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -35,17 +33,6 @@ class Square extends PositionComponent with HasGameRef<Priority>, Tappable {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class Priority extends FlameGame with HasTappableComponents {
|
||||
|
||||
Reference in New Issue
Block a user