mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	Transforming PaletteEntry#paint into a full method and adding more colors to BasicPalette (#725)
* Transforming PaletteEntry#paint into a full method * Fixing some errors that went unoticed * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * followup * format Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
This commit is contained in:
		| @ -4,7 +4,7 @@ import 'package:flame/components.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
|  | ||||
| class SquareComponent extends PositionComponent { | ||||
|   Paint paint = BasicPalette.white.paint; | ||||
|   Paint paint = BasicPalette.white.paint(); | ||||
|  | ||||
|   SquareComponent() { | ||||
|     size = Vector2.all(100.0); | ||||
|  | ||||
| @ -7,9 +7,9 @@ import 'package:flame/extensions.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| final _whitePaint = BasicPalette.white.paint; | ||||
| final _bluePaint = Paint()..color = const Color(0xFF0000FF); | ||||
| final _greenPaint = Paint()..color = const Color(0xFF00FF00); | ||||
| final _whitePaint = BasicPalette.white.paint(); | ||||
| final _bluePaint = BasicPalette.blue.paint(); | ||||
| final _greenPaint = BasicPalette.green.paint(); | ||||
|  | ||||
| class JoystickPlayer extends Component implements JoystickListener { | ||||
|   static const speed = 32.0; | ||||
|  | ||||
| @ -6,7 +6,7 @@ import 'package:flame/palette.dart'; | ||||
| import 'package:flutter/services.dart' show RawKeyDownEvent, RawKeyEvent; | ||||
|  | ||||
| class KeyboardGame extends Game with KeyboardEvents { | ||||
|   static final Paint white = BasicPalette.white.paint; | ||||
|   static final Paint white = BasicPalette.white.paint(); | ||||
|   static const int speed = 200; | ||||
|  | ||||
|   Rect rect = const Rect.fromLTWH(0, 100, 100, 100); | ||||
|  | ||||
| @ -7,8 +7,8 @@ import 'package:flutter/material.dart'; | ||||
|  | ||||
| class MouseMovementGame extends BaseGame with MouseMovementDetector { | ||||
|   static const speed = 200; | ||||
|   static final Paint blue = Paint()..color = const Color(0xFF0000FF); | ||||
|   static final Paint white = BasicPalette.white.paint; | ||||
|   static final Paint _blue = BasicPalette.blue.paint(); | ||||
|   static final Paint _white = BasicPalette.white.paint(); | ||||
|   static final Vector2 objSize = Vector2.all(50); | ||||
|  | ||||
|   Vector2 position = Vector2(0, 0); | ||||
| @ -28,7 +28,7 @@ class MouseMovementGame extends BaseGame with MouseMovementDetector { | ||||
|     super.render(canvas); | ||||
|     canvas.drawRect( | ||||
|       _toRect(), | ||||
|       onTarget ? blue : white, | ||||
|       onTarget ? _blue : _white, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|  | ||||
| @ -6,7 +6,7 @@ import 'package:flutter/material.dart'; | ||||
|  | ||||
| /// Includes an example including advanced detectors | ||||
| class MultitapGame extends BaseGame with MultiTouchTapDetector { | ||||
|   static final whitePaint = BasicPalette.white.paint; | ||||
|   static final whitePaint = BasicPalette.white.paint(); | ||||
|   static final tapSize = Vector2.all(50); | ||||
|  | ||||
|   final Map<int, Rect> taps = {}; | ||||
|  | ||||
| @ -7,7 +7,7 @@ import 'package:flutter/material.dart'; | ||||
| /// Showcases how to mix two advanced detectors | ||||
| class MultitapAdvancedGame extends BaseGame | ||||
|     with MultiTouchTapDetector, MultiTouchDragDetector { | ||||
|   static final whitePaint = BasicPalette.white.paint; | ||||
|   static final whitePaint = BasicPalette.white.paint(); | ||||
|   static final tapSize = Vector2.all(50); | ||||
|  | ||||
|   final Map<int, Rect> taps = {}; | ||||
|  | ||||
| @ -14,7 +14,7 @@ class TapableSquare extends PositionComponent with Tapable { | ||||
|       rng.nextInt(256), | ||||
|       0.9, | ||||
|     ); | ||||
|     return PaletteEntry(color).paint; | ||||
|     return PaletteEntry(color).paint(); | ||||
|   } | ||||
|  | ||||
|   Paint currentPaint; | ||||
|  | ||||
| @ -9,7 +9,7 @@ import 'package:flame/extensions.dart'; | ||||
| class ScrollGame extends BaseGame with ScrollDetector { | ||||
|   static const speed = 2000.0; | ||||
|   final _size = Vector2.all(50); | ||||
|   final _paint = BasicPalette.white.paint; | ||||
|   final _paint = BasicPalette.white.paint(); | ||||
|  | ||||
|   Vector2 position = Vector2.all(100); | ||||
|   Vector2? target; | ||||
|  | ||||
| @ -6,6 +6,8 @@ | ||||
|  - Updated the documentation for the supported platforms | ||||
|  - Add clear function to BaseGame to allow the removal of all components | ||||
|  - Moving tutorials to the Flame main repository | ||||
|  - Transforming `PaletteEntry.paint` to be a method instead of a getter | ||||
|  - Adding some more basic colors entries to the `BasicPalette` | ||||
|  - Fixing Flutter and Dart version constraints | ||||
|  - Exporting Images and AssetsCache | ||||
|  | ||||
|  | ||||
| @ -15,19 +15,13 @@ void main() { | ||||
|   ); | ||||
| } | ||||
|  | ||||
| class Palette { | ||||
|   static const PaletteEntry white = BasicPalette.white; | ||||
|   static const PaletteEntry red = PaletteEntry(Color(0xFFFF0000)); | ||||
|   static const PaletteEntry blue = PaletteEntry(Color(0xFF0000FF)); | ||||
| } | ||||
|  | ||||
| class Square extends PositionComponent { | ||||
|   static const speed = 0.25; | ||||
|   static const squareSize = 128.0; | ||||
|  | ||||
|   static Paint white = Palette.white.paint; | ||||
|   static Paint red = Palette.red.paint; | ||||
|   static Paint blue = Palette.blue.paint; | ||||
|   static Paint white = BasicPalette.white.paint(); | ||||
|   static Paint red = BasicPalette.red.paint(); | ||||
|   static Paint blue = BasicPalette.blue.paint(); | ||||
|  | ||||
|   @override | ||||
|   void render(Canvas c) { | ||||
|  | ||||
| @ -26,7 +26,7 @@ class TextBoxConfig { | ||||
| } | ||||
|  | ||||
| class TextBoxComponent extends PositionComponent { | ||||
|   static final Paint _imagePaint = BasicPalette.white.paint | ||||
|   static final Paint _imagePaint = BasicPalette.white.paint() | ||||
|     ..filterQuality = FilterQuality.high; | ||||
|   Vector2 _gameSize = Vector2.zero(); | ||||
|  | ||||
|  | ||||
| @ -11,6 +11,8 @@ import 'sprite.dart'; | ||||
| /// in the direction in which they are located and expanding the center in both directions. | ||||
| /// That allows you to have non distorted borders. | ||||
| class NineTileBox { | ||||
|   static final _whitePaint = BasicPalette.white.paint(); | ||||
|  | ||||
|   /// The sprite used to render the box, must be a 3x3 grid of square tiles. | ||||
|   Sprite sprite; | ||||
|  | ||||
| @ -86,6 +88,6 @@ class NineTileBox { | ||||
|     final xSrc = sprite.src.left + _tileSizeDouble * i; | ||||
|     final ySrc = sprite.src.top + _tileSizeDouble * j; | ||||
|     final src = Rect.fromLTWH(xSrc, ySrc, _tileSizeDouble, _tileSizeDouble); | ||||
|     c.drawImageRect(sprite.image, src, dest, BasicPalette.white.paint); | ||||
|     c.drawImageRect(sprite.image, src, dest, _whitePaint); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -3,7 +3,7 @@ import 'dart:ui'; | ||||
| class PaletteEntry { | ||||
|   final Color color; | ||||
|  | ||||
|   Paint get paint => Paint()..color = color; | ||||
|   Paint paint() => Paint()..color = color; | ||||
|  | ||||
|   const PaletteEntry(this.color); | ||||
|  | ||||
| @ -27,4 +27,8 @@ class PaletteEntry { | ||||
| class BasicPalette { | ||||
|   static const PaletteEntry white = PaletteEntry(Color(0xFFFFFFFF)); | ||||
|   static const PaletteEntry black = PaletteEntry(Color(0xFF000000)); | ||||
|   static const PaletteEntry red = PaletteEntry(Color(0xFFFF0000)); | ||||
|   static const PaletteEntry green = PaletteEntry(Color(0xFF00FF00)); | ||||
|   static const PaletteEntry blue = PaletteEntry(Color(0xFF0000FF)); | ||||
|   static const PaletteEntry magenta = PaletteEntry(Color(0xFFFF00FF)); | ||||
| } | ||||
|  | ||||
| @ -9,7 +9,7 @@ import 'flame.dart'; | ||||
| import 'palette.dart'; | ||||
|  | ||||
| class Sprite { | ||||
|   Paint paint = BasicPalette.white.paint; | ||||
|   Paint paint = BasicPalette.white.paint(); | ||||
|   Image image; | ||||
|   Rect src = Rect.zero; | ||||
|  | ||||
|  | ||||
| @ -108,7 +108,7 @@ Right, now we have all the data and variables we need to start implementing our | ||||
| class MyGame extends Game { | ||||
|   // BasicPalette is a help class from Flame, which provides default, pre built instances | ||||
|   // of Paint that can be used by your game | ||||
|   static final squarePaint = BasicPalette.white.paint; | ||||
|   static final squarePaint = BasicPalette.white.paint(); | ||||
|  | ||||
|   // Update mehod ommited | ||||
|  | ||||
|  | ||||
| @ -13,7 +13,7 @@ void main() { | ||||
|  | ||||
| class MyGame extends Game { | ||||
|   static const int squareSpeed = 400; | ||||
|   static final squarePaint = BasicPalette.white.paint; | ||||
|   static final squarePaint = BasicPalette.white.paint(); | ||||
|   late Rect squarePos; | ||||
|   int squareDirection = 1; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Erick
					Erick