mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	following flutter pattern for examples
This commit is contained in:
		
							
								
								
									
										52
									
								
								example/lib/main.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								example/lib/main.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| import 'dart:math' as math; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/component.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| void main() => runApp(new MyGame().widget); | ||||
|  | ||||
| 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; | ||||
|  | ||||
|   Square(double size) { | ||||
|     width = height = size; | ||||
|     anchor = Anchor.center; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void resize(Size size) { | ||||
|     x = size.width / 2; | ||||
|     y = size.height / 2; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void render(Canvas c) { | ||||
|     prepareCanvas(c); | ||||
|  | ||||
|     c.drawRect(Rect.fromLTWH(0, 0, width, height), Palette.white.paint); | ||||
|     c.drawRect(Rect.fromLTWH(0, 0, 3, 3), Palette.red.paint); | ||||
|     c.drawRect(Rect.fromLTWH(width / 2, height / 2, 3, 3), Palette.blue.paint); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void update(double t) { | ||||
|     angle += SPEED * t; | ||||
|     angle %= (2 * math.pi); | ||||
|   } | ||||
| } | ||||
|  | ||||
| class MyGame extends BaseGame { | ||||
|   MyGame() { | ||||
|     add(new Square(64.0)); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Luan Nico
					Luan Nico