mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	Move files to src and comply with the dart package layout convention (#621)
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
This commit is contained in:
		| @ -20,6 +20,7 @@ | ||||
|  - Updated the `widgets.md` documentation | ||||
|  - Removing methods `initialDimensions` and `removeGestureRecognizer` to avoid confusion | ||||
|  - Adding standard for `SpriteComponent` and `SpriteAnimationComponent` constructors | ||||
|  - Move files to comply with the dart package layout convention | ||||
|  | ||||
| ## 1.0.0-rc5 | ||||
|  - Option for overlays to be already visible on the GameWidget | ||||
|  | ||||
| @ -1,9 +1,7 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flutter/gestures.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/sprite_animation.dart'; | ||||
| import 'package:flame/components/sprite_animation_component.dart'; | ||||
| import 'package:flutter/material.dart' hide Image; | ||||
| import 'dart:ui'; | ||||
|  | ||||
|  | ||||
| @ -1,7 +1,5 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/sprite_animation.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components/sprite_animation_component.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| void main() async { | ||||
|  | ||||
| @ -1,8 +1,5 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/mixins/has_game_ref.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| void main() async { | ||||
|  | ||||
| @ -1,8 +1,6 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components/sprite_component.dart'; | ||||
| import 'package:flame/text_config.dart'; | ||||
|  | ||||
| import 'package:flutter/material.dart' hide Image; | ||||
|  | ||||
|  | ||||
| @ -1,13 +1,9 @@ | ||||
| import 'package:flame/effects/combined_effect.dart'; | ||||
| import 'package:flame/effects/move_effect.dart'; | ||||
| import 'package:flame/effects/scale_effect.dart'; | ||||
| import 'package:flame/effects/rotate_effect.dart'; | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| import './square.dart'; | ||||
|  | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
|  | ||||
| class Square extends PositionComponent { | ||||
|   final Paint _paint; | ||||
|  | ||||
| @ -1,8 +1,5 @@ | ||||
| import 'package:flame/effects/move_effect.dart'; | ||||
| import 'package:flame/effects/scale_effect.dart'; | ||||
| import 'package:flame/effects/rotate_effect.dart'; | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
|  | ||||
| class Square extends PositionComponent { | ||||
|   final Paint _paint; | ||||
|  | ||||
| @ -1,13 +1,8 @@ | ||||
| import 'package:flame/effects/combined_effect.dart'; | ||||
| import 'package:flame/effects/move_effect.dart'; | ||||
| import 'package:flame/effects/scale_effect.dart'; | ||||
| import 'package:flame/effects/rotate_effect.dart'; | ||||
| import 'package:flame/effects/sequence_effect.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| import './square.dart'; | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
|  | ||||
| class Square extends PositionComponent { | ||||
|   final Paint _paint; | ||||
|  | ||||
| @ -1,9 +1,9 @@ | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/effects/effects.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flutter/animation.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| import './square.dart'; | ||||
|  | ||||
|  | ||||
| @ -1,10 +1,10 @@ | ||||
| import 'dart:math'; | ||||
|  | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/effects/effects.dart'; | ||||
|  | ||||
| import './square.dart'; | ||||
|  | ||||
|  | ||||
| @ -1,9 +1,8 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/effects.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/effects/effects.dart'; | ||||
|  | ||||
| import './square.dart'; | ||||
|  | ||||
|  | ||||
| @ -1,10 +1,7 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
|  | ||||
| class Square extends PositionComponent { | ||||
|   static final _paint = Paint()..color = const Color(0xFFFFFFFF); | ||||
|  | ||||
|  | ||||
| @ -1,11 +1,8 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/mixins/draggable.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flutter/material.dart' hide Draggable; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
|  | ||||
| void main() { | ||||
|   final widget = Container( | ||||
|  | ||||
| @ -2,8 +2,7 @@ import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
|  | ||||
| void main() { | ||||
|   runApp( | ||||
|  | ||||
| @ -1,11 +1,9 @@ | ||||
| import 'dart:math' as math; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
| import 'package:flame/components/mixins/tapable.dart'; | ||||
|  | ||||
| void main() { | ||||
|   final game = MyGame(); | ||||
|  | ||||
| @ -2,8 +2,7 @@ import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/extensions/offset.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
|  | ||||
| void main() { | ||||
|   final game = MyGame(); | ||||
|  | ||||
| @ -1,9 +1,7 @@ | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
| import 'package:flame/components/mixins/tapable.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
|  | ||||
| void main() { | ||||
|   runApp( | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| import 'package:flame/components/sprite_component.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/components/isometric_tile_map_component.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/sprite.dart'; | ||||
| import 'package:flame/spritesheet.dart'; | ||||
| import 'package:flutter/gestures.dart'; | ||||
| import 'package:flutter/material.dart' hide Image; | ||||
|  | ||||
| @ -1,8 +1,6 @@ | ||||
| import 'package:flame/components/joystick/joystick_action.dart'; | ||||
| import 'package:flame/components/joystick/joystick_component.dart'; | ||||
| import 'package:flame/components/joystick/joystick_directional.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/joystick.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| import 'player.dart'; | ||||
|  | ||||
| @ -1,11 +1,9 @@ | ||||
| import 'dart:math'; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/components/component.dart'; | ||||
| import 'package:flame/components/joystick/joystick_component.dart'; | ||||
| import 'package:flame/components/joystick/joystick_events.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/joystick.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
|  | ||||
| class Player extends Component implements JoystickListener { | ||||
|   final _whitePaint = BasicPalette.white.paint; | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart' hide Animation; | ||||
| import 'package:flame/sprite.dart'; | ||||
| import 'package:flame/layers/layer.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/layers.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| void main() async { | ||||
|   Flame.initializeWidget(); | ||||
|  | ||||
|  | ||||
| @ -1,8 +1,5 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/nine_tile_box.dart'; | ||||
| import 'package:flame/sprite.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
|  | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| void main() async { | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/components/parallax_component.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
|  | ||||
| @ -1,7 +1,6 @@ | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/parallax.dart'; | ||||
| import 'package:flame/components/parallax_component.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
|  | ||||
| @ -2,29 +2,12 @@ import 'dart:async'; | ||||
| import 'dart:math'; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/sprite_animation.dart'; | ||||
| import 'package:flame/components/component.dart'; | ||||
| import 'package:flame/particles/circle_particle.dart'; | ||||
| import 'package:flame/particles/composed_particle.dart'; | ||||
| import 'package:flame/particles/curved_particle.dart'; | ||||
| import 'package:flame/particles/moving_particle.dart'; | ||||
| import 'package:flame/particles/sprite_particle.dart'; | ||||
| import 'package:flame/particles/translated_particle.dart'; | ||||
| import 'package:flame/particles/computed_particle.dart'; | ||||
| import 'package:flame/particles/image_particle.dart'; | ||||
| import 'package:flame/particles/rotating_particle.dart'; | ||||
| import 'package:flame/particles/accelerated_particle.dart'; | ||||
| import 'package:flame/particles/paint_particle.dart'; | ||||
| import 'package:flame/particles/animation_particle.dart'; | ||||
| import 'package:flame/particles/component_particle.dart'; | ||||
| import 'package:flame/components.dart' hide Timer; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/timer.dart' as flame_timer; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/timer.dart' as flame_time; | ||||
| import 'package:flame/particle.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/sprite.dart'; | ||||
| import 'package:flame/particles.dart'; | ||||
| import 'package:flame/spritesheet.dart'; | ||||
| import 'package:flame/text_config.dart'; | ||||
| import 'package:flutter/material.dart' hide Image; | ||||
|  | ||||
| void main() async { | ||||
| @ -570,7 +553,7 @@ class SineCurve extends Curve { | ||||
| /// each 2s of registered lifetime. | ||||
| class TrafficLightComponent extends Component { | ||||
|   final Rect rect = Rect.fromCenter(center: Offset.zero, height: 32, width: 32); | ||||
|   final flame_time.Timer colorChangeTimer = flame_time.Timer(2, repeat: true); | ||||
|   final flame_timer.Timer colorChangeTimer = flame_timer.Timer(2, repeat: true); | ||||
|   final colors = <Color>[ | ||||
|     Colors.green, | ||||
|     Colors.orange, | ||||
|  | ||||
| @ -1,7 +1,5 @@ | ||||
| import 'package:flame/sprite_animation.dart'; | ||||
| import 'package:flame/components/sprite_animation_component.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flutter/material.dart' hide Image; | ||||
| import 'dart:ui'; | ||||
|  | ||||
|  | ||||
| @ -1,10 +1,9 @@ | ||||
| import 'dart:math'; | ||||
|  | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/sprite_batch.dart'; | ||||
| import 'package:flame/components/sprite_batch_component.dart'; | ||||
|  | ||||
| void main() async { | ||||
|   WidgetsFlutterBinding.ensureInitialized(); | ||||
|  | ||||
| @ -1,9 +1,8 @@ | ||||
| import 'dart:math'; | ||||
|  | ||||
| import 'package:flame/components/sprite_component.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| void main() async { | ||||
|   WidgetsFlutterBinding.ensureInitialized(); | ||||
|  | ||||
| @ -1,10 +1,10 @@ | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/sprite.dart'; | ||||
|  | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| void main() { | ||||
|   runApp( | ||||
|     GameWidget( | ||||
|  | ||||
| @ -1,6 +1,4 @@ | ||||
| import 'package:flame/components/sprite_animation_component.dart'; | ||||
| import 'package:flame/components/sprite_component.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/spritesheet.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| @ -1,11 +1,8 @@ | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/components/text_box_component.dart'; | ||||
| import 'package:flame/components/text_component.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flame/text_config.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| void main() { | ||||
|  | ||||
| @ -1,10 +1,7 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/timer.dart'; | ||||
| import 'package:flame/text_config.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/components/timer_component.dart'; | ||||
|  | ||||
| void main() { | ||||
|   runApp(MyGameApp()); | ||||
|  | ||||
| @ -1,16 +1,10 @@ | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/extensions.dart'; | ||||
| import 'package:flame/widgets.dart'; | ||||
| import 'package:flutter/material.dart' hide Animation; | ||||
| import 'package:flame/flame.dart'; | ||||
| import 'package:flame/sprite.dart'; | ||||
| import 'package:flame/spritesheet.dart'; | ||||
| import 'package:dashbook/dashbook.dart'; | ||||
|  | ||||
| import 'package:flame/widgets/nine_tile_box.dart'; | ||||
| import 'package:flame/widgets/sprite_button.dart'; | ||||
| import 'package:flame/widgets/sprite_widget.dart'; | ||||
| import 'package:flame/widgets/animation_widget.dart'; | ||||
| import 'package:flame/anchor.dart'; | ||||
|  | ||||
| Anchor parseAnchor(String name) { | ||||
|   switch (name) { | ||||
|     case 'Anchor.topLeft': | ||||
|  | ||||
| @ -1,12 +1,9 @@ | ||||
| import 'dart:math' as math; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flame/anchor.dart'; | ||||
| import 'package:flame/extensions/vector2.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/components/position_component.dart'; | ||||
| import 'package:flame/components/mixins/has_game_ref.dart'; | ||||
| import 'package:flame/components.dart'; | ||||
| import 'package:flame/game.dart'; | ||||
| import 'package:flame/gestures.dart'; | ||||
| import 'package:flame/palette.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
|  | ||||
							
								
								
									
										24
									
								
								lib/components.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								lib/components.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| export 'src/components/component.dart'; | ||||
| export 'src/components/base_component.dart'; | ||||
| export 'src/components/isometric_tile_map_component.dart'; | ||||
| export 'src/components/nine_tile_box_component.dart'; | ||||
| export 'src/components/parallax_component.dart'; | ||||
| export 'src/components/particle_component.dart'; | ||||
| export 'src/components/position_component.dart'; | ||||
| export 'src/components/sprite_animation_component.dart'; | ||||
| export 'src/components/sprite_batch_component.dart'; | ||||
| export 'src/components/sprite_component.dart'; | ||||
| export 'src/components/text_box_component.dart'; | ||||
| export 'src/components/text_component.dart'; | ||||
|  | ||||
| export 'src/timer.dart'; | ||||
| export 'joystick.dart'; | ||||
|  | ||||
| export 'src/components/mixins/draggable.dart'; | ||||
| export 'src/components/mixins/has_game_ref.dart'; | ||||
| export 'src/components/mixins/single_child_particle.dart'; | ||||
| export 'src/components/mixins/tapable.dart'; | ||||
|  | ||||
| export 'src/extensions/vector2.dart'; | ||||
| export 'src/anchor.dart'; | ||||
| export 'src/text_config.dart'; | ||||
| @ -1,23 +0,0 @@ | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import '../timer.dart'; | ||||
| import 'component.dart'; | ||||
|  | ||||
| /// Simple component which wraps a [Timer] instance allowing it to be easily used inside a [BaseGame] game. | ||||
| class TimerComponent extends Component { | ||||
|   Timer timer; | ||||
|  | ||||
|   TimerComponent(this.timer); | ||||
|  | ||||
|   @override | ||||
|   void update(double dt) { | ||||
|     super.update(dt); | ||||
|     timer.update(dt); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void render(Canvas canvas) {} | ||||
|  | ||||
|   @override | ||||
|   bool get shouldRemove => timer.finished; | ||||
| } | ||||
							
								
								
									
										9
									
								
								lib/effects.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/effects.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| export 'src/effects/combined_effect.dart'; | ||||
| export 'src/effects/effects.dart'; | ||||
| export 'src/effects/effects_handler.dart'; | ||||
| export 'src/effects/move_effect.dart'; | ||||
| export 'src/effects/rotate_effect.dart'; | ||||
| export 'src/effects/scale_effect.dart'; | ||||
| export 'src/effects/sequence_effect.dart'; | ||||
|  | ||||
| export 'src/extensions/vector2.dart'; | ||||
							
								
								
									
										5
									
								
								lib/extensions.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								lib/extensions.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| export 'src/extensions/canvas.dart'; | ||||
| export 'src/extensions/offset.dart'; | ||||
| export 'src/extensions/rect.dart'; | ||||
| export 'src/extensions/size.dart'; | ||||
| export 'src/extensions/vector2.dart'; | ||||
| @ -1,49 +1 @@ | ||||
| library flame; | ||||
|  | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| import 'assets/assets_cache.dart'; | ||||
| import 'assets/images.dart'; | ||||
| import 'util.dart'; | ||||
|  | ||||
| /// This class holds static references to some useful objects to use in your game. | ||||
| /// | ||||
| /// You can access shared instances of [AssetsCache], [Images] and [Util]. | ||||
| /// Most games should need only one instance of each, and should use this class to manage that reference. | ||||
| class Flame { | ||||
|   // Flame asset bundle, defaults to root | ||||
|   static AssetBundle _bundle; | ||||
|   static AssetBundle get bundle => _bundle ?? rootBundle; | ||||
|  | ||||
|   /// Access a shared instance of [AssetsCache] class. | ||||
|   static AssetsCache assets = AssetsCache(); | ||||
|  | ||||
|   /// Access a shared instance of the [Images] class. | ||||
|   static Images images = Images(); | ||||
|  | ||||
|   /// Access a shared instance of the [Util] class. | ||||
|   static Util util = Util(); | ||||
|  | ||||
|   static Future<void> init({ | ||||
|     AssetBundle bundle, | ||||
|     bool fullScreen = true, | ||||
|     DeviceOrientation orientation, | ||||
|   }) async { | ||||
|     initializeWidget(); | ||||
|  | ||||
|     if (fullScreen) { | ||||
|       await util.fullScreen(); | ||||
|     } | ||||
|  | ||||
|     if (orientation != null) { | ||||
|       await util.setOrientation(orientation); | ||||
|     } | ||||
|  | ||||
|     _bundle = bundle; | ||||
|   } | ||||
|  | ||||
|   static void initializeWidget() { | ||||
|     WidgetsFlutterBinding.ensureInitialized(); | ||||
|   } | ||||
| } | ||||
| export 'src/flame.dart'; | ||||
|  | ||||
| @ -1,4 +1,7 @@ | ||||
| // Keeping compatible with earlier versions of Flame | ||||
| export './game/base_game.dart'; | ||||
| export './game/game.dart'; | ||||
| export './game/game_widget.dart'; | ||||
| export 'src/game/base_game.dart'; | ||||
| export 'src/game/game.dart'; | ||||
| export 'src/game/game_widget.dart'; | ||||
|  | ||||
| export 'src/extensions/vector2.dart'; | ||||
| export 'src/fps_counter.dart'; | ||||
| export 'src/text_config.dart'; | ||||
|  | ||||
| @ -1,111 +1 @@ | ||||
| import 'package:flutter/gestures.dart'; | ||||
|  | ||||
| import 'game/game.dart'; | ||||
|  | ||||
| mixin MultiTouchTapDetector on Game { | ||||
|   void onTap(int pointerId) {} | ||||
|   void onTapCancel(int pointerId) {} | ||||
|   void onTapDown(int pointerId, TapDownDetails details) {} | ||||
|   void onTapUp(int pointerId, TapUpDetails details) {} | ||||
|   void onLongTapDown(int pointerId, TapDownDetails details) {} | ||||
| } | ||||
|  | ||||
| class DragEvent extends Drag { | ||||
|   final Offset initialPosition; | ||||
|  | ||||
|   DragEvent(this.initialPosition); | ||||
|  | ||||
|   void Function(DragUpdateDetails) onUpdate; | ||||
|   void Function() onCancel; | ||||
|   void Function(DragEndDetails) onEnd; | ||||
|  | ||||
|   @override | ||||
|   void update(details) { | ||||
|     onUpdate?.call(details); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void cancel() { | ||||
|     onCancel?.call(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void end(details) { | ||||
|     onEnd?.call(details); | ||||
|   } | ||||
| } | ||||
|  | ||||
| mixin MultiTouchDragDetector on Game { | ||||
|   void onReceiveDrag(DragEvent drag) {} | ||||
| } | ||||
|  | ||||
| // Basic touch detectors | ||||
| mixin TapDetector on Game { | ||||
|   void onTap() {} | ||||
|   void onTapCancel() {} | ||||
|   void onTapDown(TapDownDetails details) {} | ||||
|   void onTapUp(TapUpDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin SecondaryTapDetector on Game { | ||||
|   void onSecondaryTapDown(TapDownDetails details) {} | ||||
|   void onSecondaryTapUp(TapUpDetails details) {} | ||||
|   void onSecondaryTapCancel() {} | ||||
| } | ||||
|  | ||||
| mixin DoubleTapDetector on Game { | ||||
|   void onDoubleTap() {} | ||||
| } | ||||
|  | ||||
| mixin LongPressDetector on Game { | ||||
|   void onLongPress() {} | ||||
|   void onLongPressStart(LongPressStartDetails details) {} | ||||
|   void onLongPressMoveUpdate(LongPressMoveUpdateDetails details) {} | ||||
|   void onLongPressUp() {} | ||||
|   void onLongPressEnd(LongPressEndDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin VerticalDragDetector on Game { | ||||
|   void onVerticalDragDown(DragDownDetails details) {} | ||||
|   void onVerticalDragStart(DragStartDetails details) {} | ||||
|   void onVerticalDragUpdate(DragUpdateDetails details) {} | ||||
|   void onVerticalDragEnd(DragEndDetails details) {} | ||||
|   void onVerticalDragCancel() {} | ||||
| } | ||||
|  | ||||
| mixin HorizontalDragDetector on Game { | ||||
|   void onHorizontalDragDown(DragDownDetails details) {} | ||||
|   void onHorizontalDragStart(DragStartDetails details) {} | ||||
|   void onHorizontalDragUpdate(DragUpdateDetails details) {} | ||||
|   void onHorizontalDragEnd(DragEndDetails details) {} | ||||
|   void onHorizontalDragCancel() {} | ||||
| } | ||||
|  | ||||
| mixin ForcePressDetector on Game { | ||||
|   void onForcePressStart(ForcePressDetails details) {} | ||||
|   void onForcePressPeak(ForcePressDetails details) {} | ||||
|   void onForcePressUpdate(ForcePressDetails details) {} | ||||
|   void onForcePressEnd(ForcePressDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin PanDetector on Game { | ||||
|   void onPanDown(DragDownDetails details) {} | ||||
|   void onPanStart(DragStartDetails details) {} | ||||
|   void onPanUpdate(DragUpdateDetails details) {} | ||||
|   void onPanEnd(DragEndDetails details) {} | ||||
|   void onPanCancel() {} | ||||
| } | ||||
|  | ||||
| mixin ScaleDetector on Game { | ||||
|   void onScaleStart(ScaleStartDetails details) {} | ||||
|   void onScaleUpdate(ScaleUpdateDetails details) {} | ||||
|   void onScaleEnd(ScaleEndDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin MouseMovementDetector on Game { | ||||
|   void onMouseMove(PointerHoverEvent event) {} | ||||
| } | ||||
|  | ||||
| mixin ScrollDetector on Game { | ||||
|   void onScroll(PointerScrollEvent event) {} | ||||
| } | ||||
| export 'src/gestures.dart'; | ||||
|  | ||||
							
								
								
									
										7
									
								
								lib/joystick.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								lib/joystick.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| export 'src/components/joystick/joystick_action.dart'; | ||||
| export 'src/components/joystick/joystick_component.dart'; | ||||
| export 'src/components/joystick/joystick_directional.dart'; | ||||
| export 'src/components/joystick/joystick_events.dart'; | ||||
| export 'src/components/joystick/joystick_utils.dart'; | ||||
|  | ||||
| export 'src/sprite.dart'; | ||||
| @ -1,7 +1 @@ | ||||
| import 'package:flutter/services.dart'; | ||||
|  | ||||
| import 'game.dart'; | ||||
|  | ||||
| mixin KeyboardEvents on Game { | ||||
|   void onKeyEvent(RawKeyEvent event); | ||||
| } | ||||
| export 'src/keyboard.dart'; | ||||
|  | ||||
							
								
								
									
										2
									
								
								lib/layers.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								lib/layers.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| export 'src/layers/layer.dart'; | ||||
| export 'src/layers/processors.dart'; | ||||
| @ -1,30 +1 @@ | ||||
| import 'dart:ui'; | ||||
|  | ||||
| class PaletteEntry { | ||||
|   final Color color; | ||||
|  | ||||
|   Paint get paint => Paint()..color = color; | ||||
|  | ||||
|   const PaletteEntry(this.color); | ||||
|  | ||||
|   PaletteEntry withAlpha(int alpha) { | ||||
|     return PaletteEntry(color.withAlpha(alpha)); | ||||
|   } | ||||
|  | ||||
|   PaletteEntry withRed(int red) { | ||||
|     return PaletteEntry(color.withRed(red)); | ||||
|   } | ||||
|  | ||||
|   PaletteEntry withGreen(int green) { | ||||
|     return PaletteEntry(color.withGreen(green)); | ||||
|   } | ||||
|  | ||||
|   PaletteEntry withBlue(int blue) { | ||||
|     return PaletteEntry(color.withBlue(blue)); | ||||
|   } | ||||
| } | ||||
|  | ||||
| class BasicPalette { | ||||
|   static const PaletteEntry white = PaletteEntry(Color(0xFFFFFFFF)); | ||||
|   static const PaletteEntry black = PaletteEntry(Color(0xFF000000)); | ||||
| } | ||||
| export 'src/palette.dart'; | ||||
|  | ||||
| @ -1,315 +1 @@ | ||||
| import 'dart:async'; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flutter/painting.dart'; | ||||
|  | ||||
| import 'assets/images.dart'; | ||||
| import 'extensions/rect.dart'; | ||||
| import 'extensions/vector2.dart'; | ||||
| import 'flame.dart'; | ||||
| import 'game/game.dart'; | ||||
|  | ||||
| extension ParallaxExtension on Game { | ||||
|   Future<Parallax> loadParallax( | ||||
|     List<String> paths, { | ||||
|     Vector2 baseVelocity, | ||||
|     Vector2 velocityMultiplierDelta, | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|   }) { | ||||
|     return Parallax.load( | ||||
|       paths, | ||||
|       baseVelocity: baseVelocity, | ||||
|       velocityMultiplierDelta: velocityMultiplierDelta, | ||||
|       repeat: repeat, | ||||
|       alignment: alignment, | ||||
|       fill: fill, | ||||
|       images: images, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   Future<ParallaxImage> loadParallaxImage( | ||||
|     String path, { | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|   }) { | ||||
|     return ParallaxImage.load( | ||||
|       path, | ||||
|       repeat: repeat, | ||||
|       alignment: alignment, | ||||
|       fill: fill, | ||||
|       images: images, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   Future<ParallaxLayer> loadParallaxLayer( | ||||
|     String path, { | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|     Vector2 velocityMultiplier, | ||||
|   }) { | ||||
|     return ParallaxLayer.load( | ||||
|       path, | ||||
|       velocityMultiplier: velocityMultiplier, | ||||
|       repeat: repeat, | ||||
|       alignment: alignment, | ||||
|       fill: fill, | ||||
|       images: images, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
| /// Specifications with a path to an image and how it should be drawn in | ||||
| /// relation to the device screen | ||||
| class ParallaxImage { | ||||
|   /// The image | ||||
|   final Image image; | ||||
|  | ||||
|   /// If and how the image should be repeated on the canvas | ||||
|   final ImageRepeat repeat; | ||||
|  | ||||
|   /// How to align the image in relation to the screen | ||||
|   final Alignment alignment; | ||||
|  | ||||
|   /// How to fill the screen with the image, always proportionally scaled. | ||||
|   final LayerFill fill; | ||||
|  | ||||
|   ParallaxImage( | ||||
|     this.image, { | ||||
|     this.repeat = ImageRepeat.repeatX, | ||||
|     this.alignment = Alignment.bottomLeft, | ||||
|     this.fill = LayerFill.height, | ||||
|   }); | ||||
|  | ||||
|   /// Takes a path of an image, and optionally arguments for how the image should | ||||
|   /// repeat ([repeat]), which edge it should align with ([alignment]), which axis | ||||
|   /// it should fill the image on ([fill]) and [images] which is the image cache | ||||
|   /// that should be used. If no image cache is set, the global flame cache is used. | ||||
|   static Future<ParallaxImage> load( | ||||
|     String path, { | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|     Images images, | ||||
|   }) async { | ||||
|     images ??= Flame.images; | ||||
|     return ParallaxImage( | ||||
|       await images.load(path), | ||||
|       repeat: repeat, | ||||
|       alignment: alignment, | ||||
|       fill: fill, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
| /// Represents one layer in the parallax, draws out an image on a canvas in the | ||||
| /// manner specified by the parallaxImage | ||||
| class ParallaxLayer { | ||||
|   final ParallaxImage parallaxImage; | ||||
|   Vector2 velocityMultiplier; | ||||
|   Rect _paintArea; | ||||
|   Vector2 _scroll; | ||||
|   Vector2 _imageSize; | ||||
|   double _scale = 1.0; | ||||
|  | ||||
|   /// [parallaxImage] is the representation of the image with data of how the | ||||
|   /// image should behave. | ||||
|   /// [velocityMultiplier] will be used to determine the velocity of the layer by | ||||
|   /// multiplying the [baseVelocity] with the [velocityMultiplier]. | ||||
|   ParallaxLayer( | ||||
|     this.parallaxImage, { | ||||
|     Vector2 velocityMultiplier, | ||||
|   }) : velocityMultiplier = velocityMultiplier ?? Vector2.all(1.0); | ||||
|  | ||||
|   Vector2 currentOffset() => _scroll; | ||||
|  | ||||
|   void resize(Vector2 size) { | ||||
|     double scale(LayerFill fill) { | ||||
|       switch (fill) { | ||||
|         case LayerFill.height: | ||||
|           return parallaxImage.image.height / size.y; | ||||
|         case LayerFill.width: | ||||
|           return parallaxImage.image.width / size.x; | ||||
|         default: | ||||
|           return _scale; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     _scale = scale(parallaxImage.fill); | ||||
|  | ||||
|     // The image size so that it fulfills the LayerFill parameter | ||||
|     _imageSize = Vector2Extension.fromInts( | ||||
|           parallaxImage.image.width, | ||||
|           parallaxImage.image.height, | ||||
|         ) / | ||||
|         _scale; | ||||
|  | ||||
|     // Number of images that can fit on the canvas plus one | ||||
|     // to have something to scroll to without leaving canvas empty | ||||
|     final Vector2 count = Vector2.all(1) + (size.clone()..divide(_imageSize)); | ||||
|  | ||||
|     // Percentage of the image size that will overflow | ||||
|     final Vector2 overflow = ((_imageSize.clone()..multiply(count)) - size) | ||||
|       ..divide(_imageSize); | ||||
|  | ||||
|     // Align image to correct side of the screen | ||||
|     final alignment = parallaxImage.alignment; | ||||
|     final marginX = alignment.x == 0 ? overflow.x / 2 : alignment.x; | ||||
|     final marginY = alignment.y == 0 ? overflow.y / 2 : alignment.y; | ||||
|     _scroll ??= Vector2(marginX, marginY); | ||||
|  | ||||
|     // Size of the area to paint the images on | ||||
|     final Vector2 paintSize = count..multiply(_imageSize); | ||||
|     _paintArea = paintSize.toRect(); | ||||
|   } | ||||
|  | ||||
|   void update(Vector2 delta) { | ||||
|     // Scale the delta so that images that are larger don't scroll faster | ||||
|     _scroll += delta.clone()..divide(_imageSize); | ||||
|     switch (parallaxImage.repeat) { | ||||
|       case ImageRepeat.repeat: | ||||
|         _scroll = Vector2(_scroll.x % 1, _scroll.y % 1); | ||||
|         break; | ||||
|       case ImageRepeat.repeatX: | ||||
|         _scroll = Vector2(_scroll.x % 1, _scroll.y); | ||||
|         break; | ||||
|       case ImageRepeat.repeatY: | ||||
|         _scroll = Vector2(_scroll.x, _scroll.y % 1); | ||||
|         break; | ||||
|       case ImageRepeat.noRepeat: | ||||
|         break; | ||||
|     } | ||||
|  | ||||
|     final Vector2 scrollPosition = _scroll.clone()..multiply(_imageSize); | ||||
|     _paintArea = Rect.fromLTWH( | ||||
|       -scrollPosition.x, | ||||
|       -scrollPosition.y, | ||||
|       _paintArea.width, | ||||
|       _paintArea.height, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   void render(Canvas canvas) { | ||||
|     paintImage( | ||||
|       canvas: canvas, | ||||
|       image: parallaxImage.image, | ||||
|       rect: _paintArea, | ||||
|       repeat: parallaxImage.repeat, | ||||
|       scale: _scale, | ||||
|       alignment: parallaxImage.alignment, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   /// Takes a path of an image, and optionally arguments for how the image should | ||||
|   /// repeat ([repeat]), which edge it should align with ([alignment]), which axis | ||||
|   /// it should fill the image on ([fill]) and [images] which is the image cache | ||||
|   /// that should be used. If no image cache is set, the global flame cache is used. | ||||
|   static Future<ParallaxLayer> load( | ||||
|     String path, { | ||||
|     Vector2 velocityMultiplier, | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|     Images images, | ||||
|   }) async { | ||||
|     return ParallaxLayer( | ||||
|       await ParallaxImage.load( | ||||
|         path, | ||||
|         repeat: repeat, | ||||
|         alignment: alignment, | ||||
|         fill: fill, | ||||
|         images: images, | ||||
|       ), | ||||
|       velocityMultiplier: velocityMultiplier, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
| /// How to fill the screen with the image, always proportionally scaled. | ||||
| enum LayerFill { height, width, none } | ||||
|  | ||||
| /// A full parallax, several layers of images drawn out on the screen and each | ||||
| /// layer moves with different velocities to give an effect of depth. | ||||
| class Parallax { | ||||
|   Vector2 baseVelocity; | ||||
|   final List<ParallaxLayer> layers; | ||||
|  | ||||
|   Parallax( | ||||
|     this.layers, { | ||||
|     Vector2 baseVelocity, | ||||
|   }) : baseVelocity = baseVelocity ?? Vector2.zero(); | ||||
|  | ||||
|   /// The base offset of the parallax, can be used in an outer update loop | ||||
|   /// if you want to transition the parallax to a certain position. | ||||
|   Vector2 currentOffset() => layers[0].currentOffset(); | ||||
|  | ||||
|   /// If the `ParallaxComponent` isn't used your own wrapper needs to call this | ||||
|   /// on creation. | ||||
|   void resize(Vector2 size) => layers.forEach((layer) => layer.resize(size)); | ||||
|  | ||||
|   void update(double t) { | ||||
|     layers.forEach((layer) { | ||||
|       layer.update( | ||||
|         (baseVelocity.clone()..multiply(layer.velocityMultiplier)) * t, | ||||
|       ); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   /// Note that this method only should be used if all of your layers should | ||||
|   /// have the same layer arguments (how the images should be repeated, aligned | ||||
|   /// and filled), otherwise load the [ParallaxLayer]s individually and use the | ||||
|   /// normal constructor. | ||||
|   /// | ||||
|   /// [load] takes a list of paths to all the images that you want to use in the | ||||
|   /// parallax. | ||||
|   /// Optionally arguments for the [baseVelocity] and [layerDelta] can be passed | ||||
|   /// in, [baseVelocity] defines what the base velocity of the layers should be | ||||
|   /// and [velocityMultiplierDelta] defines how the velocity should change the | ||||
|   /// closer the layer is ([velocityMultiplierDelta ^ n], where n is the | ||||
|   /// layer index). | ||||
|   /// Arguments for how all the images should repeat ([repeat]), | ||||
|   /// which edge it should align with ([alignment]), which axis it should fill | ||||
|   /// the image on ([fill]) and [images] which is the image cache that should be | ||||
|   /// used can also be passed in. | ||||
|   /// If no image cache is set, the global flame cache is used. | ||||
|   static Future<Parallax> load( | ||||
|     List<String> paths, { | ||||
|     Vector2 baseVelocity, | ||||
|     Vector2 velocityMultiplierDelta, | ||||
|     ImageRepeat repeat = ImageRepeat.repeatX, | ||||
|     Alignment alignment = Alignment.bottomLeft, | ||||
|     LayerFill fill = LayerFill.height, | ||||
|     Images images, | ||||
|   }) async { | ||||
|     velocityMultiplierDelta ??= Vector2.all(1.0); | ||||
|     int depth = 0; | ||||
|     final layers = await Future.wait<ParallaxLayer>( | ||||
|       paths.map((path) async { | ||||
|         final image = ParallaxImage.load( | ||||
|           path, | ||||
|           repeat: repeat, | ||||
|           alignment: alignment, | ||||
|           fill: fill, | ||||
|           images: images, | ||||
|         ); | ||||
|         final velocityMultiplier = | ||||
|             List.filled(depth, velocityMultiplierDelta).fold<Vector2>( | ||||
|           velocityMultiplierDelta, | ||||
|           (previousValue, delta) => previousValue.clone()..multiply(delta), | ||||
|         ); | ||||
|         ++depth; | ||||
|         return ParallaxLayer( | ||||
|           await image, | ||||
|           velocityMultiplier: velocityMultiplier, | ||||
|         ); | ||||
|       }), | ||||
|     ); | ||||
|     return Parallax( | ||||
|       layers, | ||||
|       baseVelocity: baseVelocity, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| export 'src/parallax.dart'; | ||||
|  | ||||
							
								
								
									
										18
									
								
								lib/particles.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								lib/particles.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| export 'src/particles/particle.dart'; | ||||
|  | ||||
| export 'src/particles/accelerated_particle.dart'; | ||||
| export 'src/particles/animation_particle.dart'; | ||||
| export 'src/particles/circle_particle.dart'; | ||||
| export 'src/particles/component_particle.dart'; | ||||
| export 'src/particles/composed_particle.dart'; | ||||
| export 'src/particles/computed_particle.dart'; | ||||
| export 'src/particles/curved_particle.dart'; | ||||
| export 'src/particles/image_particle.dart'; | ||||
| export 'src/particles/moving_particle.dart'; | ||||
| export 'src/particles/paint_particle.dart'; | ||||
| export 'src/particles/rotating_particle.dart'; | ||||
| export 'src/particles/scaled_particle.dart'; | ||||
| export 'src/particles/sprite_particle.dart'; | ||||
| export 'src/particles/translated_particle.dart'; | ||||
|  | ||||
| export 'src/anchor.dart'; | ||||
| @ -1,27 +0,0 @@ | ||||
| class Records { | ||||
|   static void save(Profiler p) { | ||||
|     print('${p.name} : ${p.dts.last - p.dts.first} ms'); | ||||
|   } | ||||
| } | ||||
|  | ||||
| class Profiler { | ||||
|   final String name; | ||||
|   List<double> dts = []; | ||||
|  | ||||
|   Profiler(this.name) { | ||||
|     tick(); | ||||
|   } | ||||
|  | ||||
|   void tick() { | ||||
|     dts.add(currentTime()); | ||||
|   } | ||||
|  | ||||
|   void end() { | ||||
|     tick(); | ||||
|     Records.save(this); | ||||
|   } | ||||
|  | ||||
|   static double currentTime() => | ||||
|       DateTime.now().microsecondsSinceEpoch.toDouble() / | ||||
|       Duration.microsecondsPerMillisecond; | ||||
| } | ||||
| @ -1,295 +1 @@ | ||||
| import 'dart:collection'; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flutter/foundation.dart'; | ||||
|  | ||||
| import 'assets/images.dart'; | ||||
| import 'extensions/vector2.dart'; | ||||
| import 'flame.dart'; | ||||
| import 'game/game.dart'; | ||||
|  | ||||
| extension SpriteBatchExtension on Game { | ||||
|   /// Utility method to load and cache the image for a [SpriteBatch] based on its options | ||||
|   Future<SpriteBatch> loadSpriteBatch( | ||||
|     String path, { | ||||
|     Color defaultColor = const Color(0x00000000), | ||||
|     BlendMode defaultBlendMode = BlendMode.srcOver, | ||||
|     RSTransform defaultTransform, | ||||
|   }) { | ||||
|     return SpriteBatch.load( | ||||
|       path, | ||||
|       defaultColor: defaultColor, | ||||
|       defaultBlendMode: defaultBlendMode, | ||||
|       defaultTransform: defaultTransform, | ||||
|       images: images, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
| /// This is the scale value used in [BatchItem.matrix], we can't determine this from the [Batchitem.transform], | ||||
| /// but we also don't need to do so because it is already calculated inside the transform values. | ||||
| const _defaultScale = 0.0; | ||||
|  | ||||
| /// A single item in a SpriteBatch. | ||||
| /// | ||||
| /// Holds all the important information of a batch item, | ||||
| /// | ||||
| /// Web currently does not support `Canvas.drawAtlas`, so a BatchItem will | ||||
| /// automatically calculate a transform matrix based on the [transform] value, to be | ||||
| /// used when rendering on the web. It will initialize a [destination] object | ||||
| /// and a [paint] object. | ||||
| class BatchItem { | ||||
|   /// The source rectangle on the [SpriteBatch.atlas]. | ||||
|   final Rect source; | ||||
|  | ||||
|   /// The destination rectangle for the Canvas. | ||||
|   /// | ||||
|   /// It will be transformed by [matrix]. | ||||
|   final Rect destination; | ||||
|  | ||||
|   /// The transform values for this batch item. | ||||
|   final RSTransform transform; | ||||
|  | ||||
|   /// The background color for this batch item. | ||||
|   final Color color; | ||||
|  | ||||
|   /// Fallback matrix for the web. | ||||
|   /// | ||||
|   /// Because `Canvas.drawAtlas` is not supported on the web we also | ||||
|   /// build a `Matrix4` based on the [transform] values. | ||||
|   final Matrix4 matrix; | ||||
|  | ||||
|   /// Paint object used for the web. | ||||
|   final Paint paint; | ||||
|  | ||||
|   BatchItem({ | ||||
|     @required this.source, | ||||
|     @required this.transform, | ||||
|     @required this.color, | ||||
|   })  : assert(source != null), | ||||
|         assert(transform != null), | ||||
|         assert(color != null), | ||||
|         matrix = Matrix4( | ||||
|           transform.scos, transform.ssin, 0, 0, // | ||||
|           -transform.ssin, transform.scos, 0, 0, // | ||||
|           0, 0, _defaultScale, 0, // | ||||
|           transform.tx, transform.ty, 0, 1, // | ||||
|         ), | ||||
|         paint = Paint()..color = color, | ||||
|         destination = Offset.zero & source.size; | ||||
| } | ||||
|  | ||||
| /// The SpriteBatch API allows for rendering multiple items at once. | ||||
| /// | ||||
| /// This class allows for optimization when you want to draw many parts of an | ||||
| /// image onto the canvas. It is more efficient than using multiple calls to [drawImageRect] | ||||
| /// and provides more functionality by allowing each [BatchItem] to have their own transform | ||||
| /// rotation and color. | ||||
| /// | ||||
| /// By collecting all the necessary transforms on a single image and sending those transforms | ||||
| /// in a single batch to the GPU, we can render multiple parts of a single image at once. | ||||
| /// | ||||
| /// **Note**: Currently web does not support `Canvas.drawAtlas`, which SpriteBatch uses under | ||||
| /// the hood, instead it will render each [BatchItem] using `Canvas.drawImageRect`, so there | ||||
| /// might be a performance hit on web when working with many batch items. | ||||
| class SpriteBatch { | ||||
|   /// List of all the existing batch items. | ||||
|   final _batchItems = <BatchItem>[]; | ||||
|  | ||||
|   /// The sources to use on the [atlas]. | ||||
|   final _sources = <Rect>[]; | ||||
|  | ||||
|   /// The sources list shouldn't be modified directly, that is why an | ||||
|   /// [UnmodifiableListView] is used. If you want to add sources use the | ||||
|   /// [add] or [addTransform] method. | ||||
|   UnmodifiableListView<Rect> get sources { | ||||
|     return UnmodifiableListView<Rect>(_sources); | ||||
|   } | ||||
|  | ||||
|   /// The transforms that should be applied on the [_sources]. | ||||
|   final _transforms = <RSTransform>[]; | ||||
|  | ||||
|   /// The transforms list shouldn't be modified directly, that is why an | ||||
|   /// [UnmodifiableListView] is used. If you want to add transforms use the | ||||
|   /// [add] or [addTransform] method. | ||||
|   UnmodifiableListView<RSTransform> get transforms { | ||||
|     return UnmodifiableListView<RSTransform>(_transforms); | ||||
|   } | ||||
|  | ||||
|   /// The background color for the [_sources]. | ||||
|   final _colors = <Color>[]; | ||||
|  | ||||
|   /// The colors list shouldn't be modified directly, that is why an | ||||
|   /// [UnmodifiableListView] is used. If you want to add colors use the | ||||
|   /// [add] or [addTransform] method. | ||||
|   UnmodifiableListView<Color> get colors { | ||||
|     return UnmodifiableListView<Color>(_colors); | ||||
|   } | ||||
|  | ||||
|   /// The atlas used by the [SpriteBatch]. | ||||
|   final Image atlas; | ||||
|  | ||||
|   /// The default color, used as a background color for a [BatchItem]. | ||||
|   final Color defaultColor; | ||||
|  | ||||
|   /// The default transform, used when a transform was not supplied for a [BatchItem]. | ||||
|   final RSTransform defaultTransform; | ||||
|  | ||||
|   /// The default blend mode, used for blending a batch item. | ||||
|   final BlendMode defaultBlendMode; | ||||
|  | ||||
|   /// The width of the [atlas]. | ||||
|   int get width => atlas.width; | ||||
|  | ||||
|   /// The height of the [atlas]. | ||||
|   int get height => atlas.height; | ||||
|  | ||||
|   /// The size of the [atlas]. | ||||
|   Vector2 get size => Vector2Extension.fromInts(width, height); | ||||
|  | ||||
|   SpriteBatch( | ||||
|     this.atlas, { | ||||
|     this.defaultColor = const Color(0x00000000), | ||||
|     this.defaultBlendMode = BlendMode.srcOver, | ||||
|     this.defaultTransform, | ||||
|   })  : assert(atlas != null), | ||||
|         assert(defaultColor != null); | ||||
|  | ||||
|   /// Takes a path of an image, and optional arguments for the SpriteBatch. | ||||
|   /// | ||||
|   /// When the [images] is omitted, the global [Flame.images] is used. | ||||
|   static Future<SpriteBatch> load( | ||||
|     String path, { | ||||
|     Color defaultColor = const Color(0x00000000), | ||||
|     BlendMode defaultBlendMode = BlendMode.srcOver, | ||||
|     RSTransform defaultTransform, | ||||
|     Images images, | ||||
|   }) async { | ||||
|     final _images = images ?? Flame.images; | ||||
|     return SpriteBatch( | ||||
|       await _images.load(path), | ||||
|       defaultColor: defaultColor, | ||||
|       defaultTransform: defaultTransform ?? RSTransform(1, 0, 0, 0), | ||||
|       defaultBlendMode: defaultBlendMode, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   /// Add a new batch item using a RSTransform. | ||||
|   /// | ||||
|   /// The [source] parameter is the source location on the [atlas]. You can position it | ||||
|   /// on the canvas using the [offset] parameter. | ||||
|   /// | ||||
|   /// The [color] paramater allows you to render a color behind the batch item, as a background color. | ||||
|   /// | ||||
|   /// The [add] method may be a simpler way to add a batch item to the batch. However, | ||||
|   /// if there is a way to factor out the computations of the sine and cosine of the | ||||
|   /// rotation so that they can be reused over multiple calls to this constructor, | ||||
|   /// it may be more efficient to directly use this method instead. | ||||
|   void addTransform({ | ||||
|     @required Rect source, | ||||
|     RSTransform transform, | ||||
|     Color color, | ||||
|   }) { | ||||
|     final batchItem = BatchItem( | ||||
|       source: source, | ||||
|       transform: transform ??= defaultTransform ?? RSTransform(1, 0, 0, 0), | ||||
|       color: color ?? defaultColor, | ||||
|     ); | ||||
|  | ||||
|     _batchItems.add(batchItem); | ||||
|  | ||||
|     _sources.add(batchItem.source); | ||||
|     _transforms.add(batchItem.transform); | ||||
|     _colors.add(batchItem.color); | ||||
|   } | ||||
|  | ||||
|   /// Add a new batch item. | ||||
|   /// | ||||
|   /// The [source] parameter is the source location on the [atlas]. You can position it | ||||
|   /// on the canvas using the [offset] parameter. | ||||
|   /// | ||||
|   /// You can transform the sprite from its [offset] using [scale], [rotation] and [anchor]. | ||||
|   /// | ||||
|   /// The [color] paramater allows you to render a color behind the batch item, as a background color. | ||||
|   /// | ||||
|   /// This method creates a new [RSTransform] based on the given transform arguments. If many [RSTransform] objects are being | ||||
|   /// created and there is a way to factor out the computations of the sine and cosine of the rotation | ||||
|   /// (which are computed each time this method is called) and reuse them over multiple [RSTransform] objects, | ||||
|   /// it may be more efficient to directly use the more direct [addTransform] method instead. | ||||
|   void add({ | ||||
|     @required Rect source, | ||||
|     double scale = 1.0, | ||||
|     Vector2 anchor, | ||||
|     double rotation = 0, | ||||
|     Vector2 offset, | ||||
|     Color color, | ||||
|   }) { | ||||
|     anchor ??= Vector2.zero(); | ||||
|     offset ??= Vector2.zero(); | ||||
|     RSTransform transform; | ||||
|  | ||||
|     // If any of the transform arguments is different from the defaults, | ||||
|     // then we create one. This is to prevent unnecessary computations | ||||
|     // of the sine and cosine of the rotation. | ||||
|     if (scale != 1.0 || | ||||
|         anchor != Vector2.zero() || | ||||
|         rotation != 0 || | ||||
|         offset != Vector2.zero()) { | ||||
|       transform = RSTransform.fromComponents( | ||||
|         scale: scale, | ||||
|         anchorX: anchor.x, | ||||
|         anchorY: anchor.y, | ||||
|         rotation: rotation, | ||||
|         translateX: offset.x, | ||||
|         translateY: offset.y, | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     addTransform(source: source, transform: transform, color: color); | ||||
|   } | ||||
|  | ||||
|   /// Clear the SpriteBatch so it can be reused. | ||||
|   void clear() { | ||||
|     _sources.clear(); | ||||
|     _transforms.clear(); | ||||
|     _colors.clear(); | ||||
|     _batchItems.clear(); | ||||
|   } | ||||
|  | ||||
|   void render( | ||||
|     Canvas canvas, { | ||||
|     BlendMode blendMode, | ||||
|     Rect cullRect, | ||||
|     Paint paint, | ||||
|   }) { | ||||
|     paint ??= Paint(); | ||||
|  | ||||
|     if (kIsWeb) { | ||||
|       for (final batchItem in _batchItems) { | ||||
|         paint..blendMode = blendMode ?? paint.blendMode ?? defaultBlendMode; | ||||
|  | ||||
|         canvas | ||||
|           ..save() | ||||
|           ..transform(batchItem.matrix.storage) | ||||
|           ..drawRect(batchItem.destination, batchItem.paint) | ||||
|           ..drawImageRect( | ||||
|             atlas, | ||||
|             batchItem.source, | ||||
|             batchItem.destination, | ||||
|             paint, | ||||
|           ) | ||||
|           ..restore(); | ||||
|       } | ||||
|     } else { | ||||
|       canvas.drawAtlas( | ||||
|         atlas, | ||||
|         _transforms, | ||||
|         _sources, | ||||
|         _colors, | ||||
|         blendMode ?? defaultBlendMode, | ||||
|         cullRect, | ||||
|         paint, | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| export 'src/sprite_batch.dart'; | ||||
|  | ||||
| @ -1,105 +1 @@ | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:meta/meta.dart'; | ||||
|  | ||||
| import 'extensions/vector2.dart'; | ||||
| import 'sprite.dart'; | ||||
| import 'sprite_animation.dart'; | ||||
|  | ||||
| /// Utility class to help extract animations and sprites from a sprite sheet image. | ||||
| /// | ||||
| /// A sprite sheet is a single image in which several regions can be defined as individual sprites. | ||||
| /// For the purposes of this class, all of these regions must be identically sized rectangles. | ||||
| /// You can use the [Sprite] class directly if you want to have varying shapes. | ||||
| /// | ||||
| /// Each sprite in this sheet can be identified either by it's (row, col) pair or | ||||
| /// by it's "id", which is basically it's sequenced index if the image is put in a | ||||
| /// single line. The sprites can be used to compose an animation easily if they | ||||
| /// all the frames happen to be sequentially on the same row. | ||||
| /// Sprites are lazily generated but cached. | ||||
| class SpriteSheet { | ||||
|   /// The src image from which each sprite will be generated. | ||||
|   final Image image; | ||||
|  | ||||
|   /// The size of each rectangle within the image that define each sprite. | ||||
|   /// | ||||
|   /// For example, if this sprite sheet is a tile map, this would be the tile size. | ||||
|   /// If it's an animation sheet, this would be the frame size. | ||||
|   final Vector2 srcSize; | ||||
|  | ||||
|   final Map<int, Sprite> _spriteCache = {}; | ||||
|  | ||||
|   /// Creates a sprite sheet given the image and the tile size. | ||||
|   SpriteSheet({ | ||||
|     @required this.image, | ||||
|     @required this.srcSize, | ||||
|   }); | ||||
|  | ||||
|   SpriteSheet.fromColumnsAndRows({ | ||||
|     @required this.image, | ||||
|     @required int columns, | ||||
|     @required int rows, | ||||
|   }) : srcSize = Vector2( | ||||
|           image.width / columns, | ||||
|           image.height / rows, | ||||
|         ); | ||||
|  | ||||
|   /// Compute the number of columns the image has | ||||
|   /// by using the image width and tile size. | ||||
|   int get columns => image.width ~/ srcSize.x; | ||||
|  | ||||
|   /// Compute the number of rows the image has | ||||
|   /// by using the image height and tile size. | ||||
|   int get rows => image.height ~/ srcSize.y; | ||||
|  | ||||
|   /// Gets the sprite in the position (row, column) on the sprite sheet grid. | ||||
|   /// | ||||
|   /// This is lazily computed and cached for your convenience. | ||||
|   Sprite getSprite(int row, int column) { | ||||
|     return getSpriteById(row * columns + column); | ||||
|   } | ||||
|  | ||||
|   /// Gets teh sprite with id [spriteId] from the grid. | ||||
|   /// | ||||
|   /// The ids are defined as starting at 0 on the top left and going | ||||
|   /// sequentially on each row. | ||||
|   /// This is lazily computed and cached for your convenience. | ||||
|   Sprite getSpriteById(int spriteId) { | ||||
|     return _spriteCache[spriteId] ??= _computeSprite(spriteId); | ||||
|   } | ||||
|  | ||||
|   Sprite _computeSprite(int spriteId) { | ||||
|     final i = spriteId % columns; | ||||
|     final j = spriteId ~/ columns; | ||||
|     return Sprite( | ||||
|       image, | ||||
|       srcPosition: Vector2Extension.fromInts(i, j)..multiply(srcSize), | ||||
|       srcSize: srcSize, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   /// Creates a [SpriteAnimation] from this SpriteSheet, using the sequence | ||||
|   /// of sprites on a given row. | ||||
|   /// | ||||
|   /// [from] and [to] can be specified to create an animation | ||||
|   /// from a subset of the columns on the row | ||||
|   SpriteAnimation createAnimation({ | ||||
|     @required int row, | ||||
|     @required double stepTime, | ||||
|     bool loop = true, | ||||
|     int from = 0, | ||||
|     int to, | ||||
|   }) { | ||||
|     to ??= columns; | ||||
|  | ||||
|     final spriteList = List<int>.generate(to - from, (i) => from + i) | ||||
|         .map((e) => getSprite(row, e)) | ||||
|         .toList(); | ||||
|  | ||||
|     return SpriteAnimation.spriteList( | ||||
|       spriteList, | ||||
|       stepTime: stepTime, | ||||
|       loop: loop, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| export 'src/spritesheet.dart'; | ||||
|  | ||||
| @ -5,10 +5,10 @@ import 'package:meta/meta.dart'; | ||||
| import 'package:ordered_set/comparing.dart'; | ||||
| import 'package:ordered_set/ordered_set.dart'; | ||||
| 
 | ||||
| import '../../game.dart'; | ||||
| import '../effects/effects.dart'; | ||||
| import '../effects/effects_handler.dart'; | ||||
| import '../extensions/vector2.dart'; | ||||
| import '../game.dart'; | ||||
| import '../text_config.dart'; | ||||
| import 'component.dart'; | ||||
| import 'mixins/has_game_ref.dart'; | ||||
| @ -1,10 +1,9 @@ | ||||
| import 'dart:ui'; | ||||
| 
 | ||||
| import 'package:flutter/cupertino.dart'; | ||||
| import 'package:flutter/foundation.dart'; | ||||
| import 'package:flutter/painting.dart'; | ||||
| 
 | ||||
| import '../extensions/vector2.dart'; | ||||
| import '../game.dart'; | ||||
| 
 | ||||
| /// This represents a Component for your game. | ||||
| /// | ||||
| @ -1,4 +1,4 @@ | ||||
| import '../../game.dart'; | ||||
| import '../../game/game.dart'; | ||||
| 
 | ||||
| mixin HasGameRef<T extends Game> { | ||||
|   T gameRef; | ||||
| @ -1,6 +1,6 @@ | ||||
| import 'dart:ui'; | ||||
| 
 | ||||
| import '../../particle.dart'; | ||||
| import '../../particles/particle.dart'; | ||||
| 
 | ||||
| /// Implements basic behavior for nesting [Particle] instances | ||||
| /// into each other. | ||||
| @ -6,6 +6,8 @@ import '../extensions/vector2.dart'; | ||||
| import '../nine_tile_box.dart'; | ||||
| import 'position_component.dart'; | ||||
| 
 | ||||
| export '../nine_tile_box.dart'; | ||||
| 
 | ||||
| /// This class is a thin wrapper on top of [NineTileBox] as a component. | ||||
| class NineTileBoxComponent extends PositionComponent { | ||||
|   NineTileBox nineTileBox; | ||||
| @ -6,7 +6,7 @@ import 'package:flutter/painting.dart'; | ||||
| 
 | ||||
| import '../assets/images.dart'; | ||||
| import '../extensions/vector2.dart'; | ||||
| import '../game.dart'; | ||||
| import '../game/game.dart'; | ||||
| import '../parallax.dart'; | ||||
| import 'position_component.dart'; | ||||
| 
 | ||||
| @ -2,7 +2,7 @@ import 'dart:ui'; | ||||
| 
 | ||||
| import 'package:flutter/foundation.dart'; | ||||
| 
 | ||||
| import '../particle.dart'; | ||||
| import '../particles/particle.dart'; | ||||
| import 'component.dart'; | ||||
| 
 | ||||
| /// Base container for [Particle] instances to be attach | ||||
| @ -6,6 +6,8 @@ import '../extensions/vector2.dart'; | ||||
| import '../sprite_animation.dart'; | ||||
| import 'position_component.dart'; | ||||
| 
 | ||||
| export '../sprite_animation.dart'; | ||||
| 
 | ||||
| class SpriteAnimationComponent extends PositionComponent { | ||||
|   SpriteAnimation animation; | ||||
|   Paint overridePaint; | ||||
| @ -7,6 +7,8 @@ import '../sprite.dart'; | ||||
| import 'component.dart'; | ||||
| import 'position_component.dart'; | ||||
| 
 | ||||
| export '../sprite.dart'; | ||||
| 
 | ||||
| /// A [PositionComponent] that renders a single [Sprite] at the designated | ||||
| /// position, scaled to have the designated size and rotated to the specified | ||||
| /// angle. | ||||
							
								
								
									
										49
									
								
								lib/src/flame.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								lib/src/flame.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| library flame; | ||||
|  | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
|  | ||||
| import 'assets/assets_cache.dart'; | ||||
| import 'assets/images.dart'; | ||||
| import 'util.dart'; | ||||
|  | ||||
| /// This class holds static references to some useful objects to use in your game. | ||||
| /// | ||||
| /// You can access shared instances of [AssetsCache], [Images] and [Util]. | ||||
| /// Most games should need only one instance of each, and should use this class to manage that reference. | ||||
| class Flame { | ||||
|   // Flame asset bundle, defaults to root | ||||
|   static AssetBundle _bundle; | ||||
|   static AssetBundle get bundle => _bundle ?? rootBundle; | ||||
|  | ||||
|   /// Access a shared instance of [AssetsCache] class. | ||||
|   static AssetsCache assets = AssetsCache(); | ||||
|  | ||||
|   /// Access a shared instance of the [Images] class. | ||||
|   static Images images = Images(); | ||||
|  | ||||
|   /// Access a shared instance of the [Util] class. | ||||
|   static Util util = Util(); | ||||
|  | ||||
|   static Future<void> init({ | ||||
|     AssetBundle bundle, | ||||
|     bool fullScreen = true, | ||||
|     DeviceOrientation orientation, | ||||
|   }) async { | ||||
|     initializeWidget(); | ||||
|  | ||||
|     if (fullScreen) { | ||||
|       await util.fullScreen(); | ||||
|     } | ||||
|  | ||||
|     if (orientation != null) { | ||||
|       await util.setOrientation(orientation); | ||||
|     } | ||||
|  | ||||
|     _bundle = bundle; | ||||
|   } | ||||
|  | ||||
|   static void initializeWidget() { | ||||
|     WidgetsFlutterBinding.ensureInitialized(); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										111
									
								
								lib/src/gestures.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								lib/src/gestures.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | ||||
| import 'package:flutter/gestures.dart'; | ||||
|  | ||||
| import 'game/game.dart'; | ||||
|  | ||||
| mixin MultiTouchTapDetector on Game { | ||||
|   void onTap(int pointerId) {} | ||||
|   void onTapCancel(int pointerId) {} | ||||
|   void onTapDown(int pointerId, TapDownDetails details) {} | ||||
|   void onTapUp(int pointerId, TapUpDetails details) {} | ||||
|   void onLongTapDown(int pointerId, TapDownDetails details) {} | ||||
| } | ||||
|  | ||||
| class DragEvent extends Drag { | ||||
|   final Offset initialPosition; | ||||
|  | ||||
|   DragEvent(this.initialPosition); | ||||
|  | ||||
|   void Function(DragUpdateDetails) onUpdate; | ||||
|   void Function() onCancel; | ||||
|   void Function(DragEndDetails) onEnd; | ||||
|  | ||||
|   @override | ||||
|   void update(details) { | ||||
|     onUpdate?.call(details); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void cancel() { | ||||
|     onCancel?.call(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void end(details) { | ||||
|     onEnd?.call(details); | ||||
|   } | ||||
| } | ||||
|  | ||||
| mixin MultiTouchDragDetector on Game { | ||||
|   void onReceiveDrag(DragEvent drag) {} | ||||
| } | ||||
|  | ||||
| // Basic touch detectors | ||||
| mixin TapDetector on Game { | ||||
|   void onTap() {} | ||||
|   void onTapCancel() {} | ||||
|   void onTapDown(TapDownDetails details) {} | ||||
|   void onTapUp(TapUpDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin SecondaryTapDetector on Game { | ||||
|   void onSecondaryTapDown(TapDownDetails details) {} | ||||
|   void onSecondaryTapUp(TapUpDetails details) {} | ||||
|   void onSecondaryTapCancel() {} | ||||
| } | ||||
|  | ||||
| mixin DoubleTapDetector on Game { | ||||
|   void onDoubleTap() {} | ||||
| } | ||||
|  | ||||
| mixin LongPressDetector on Game { | ||||
|   void onLongPress() {} | ||||
|   void onLongPressStart(LongPressStartDetails details) {} | ||||
|   void onLongPressMoveUpdate(LongPressMoveUpdateDetails details) {} | ||||
|   void onLongPressUp() {} | ||||
|   void onLongPressEnd(LongPressEndDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin VerticalDragDetector on Game { | ||||
|   void onVerticalDragDown(DragDownDetails details) {} | ||||
|   void onVerticalDragStart(DragStartDetails details) {} | ||||
|   void onVerticalDragUpdate(DragUpdateDetails details) {} | ||||
|   void onVerticalDragEnd(DragEndDetails details) {} | ||||
|   void onVerticalDragCancel() {} | ||||
| } | ||||
|  | ||||
| mixin HorizontalDragDetector on Game { | ||||
|   void onHorizontalDragDown(DragDownDetails details) {} | ||||
|   void onHorizontalDragStart(DragStartDetails details) {} | ||||
|   void onHorizontalDragUpdate(DragUpdateDetails details) {} | ||||
|   void onHorizontalDragEnd(DragEndDetails details) {} | ||||
|   void onHorizontalDragCancel() {} | ||||
| } | ||||
|  | ||||
| mixin ForcePressDetector on Game { | ||||
|   void onForcePressStart(ForcePressDetails details) {} | ||||
|   void onForcePressPeak(ForcePressDetails details) {} | ||||
|   void onForcePressUpdate(ForcePressDetails details) {} | ||||
|   void onForcePressEnd(ForcePressDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin PanDetector on Game { | ||||
|   void onPanDown(DragDownDetails details) {} | ||||
|   void onPanStart(DragStartDetails details) {} | ||||
|   void onPanUpdate(DragUpdateDetails details) {} | ||||
|   void onPanEnd(DragEndDetails details) {} | ||||
|   void onPanCancel() {} | ||||
| } | ||||
|  | ||||
| mixin ScaleDetector on Game { | ||||
|   void onScaleStart(ScaleStartDetails details) {} | ||||
|   void onScaleUpdate(ScaleUpdateDetails details) {} | ||||
|   void onScaleEnd(ScaleEndDetails details) {} | ||||
| } | ||||
|  | ||||
| mixin MouseMovementDetector on Game { | ||||
|   void onMouseMove(PointerHoverEvent event) {} | ||||
| } | ||||
|  | ||||
| mixin ScrollDetector on Game { | ||||
|   void onScroll(PointerScrollEvent event) {} | ||||
| } | ||||
							
								
								
									
										7
									
								
								lib/src/keyboard.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								lib/src/keyboard.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| import 'package:flutter/services.dart'; | ||||
|  | ||||
| import './game/game.dart'; | ||||
|  | ||||
| mixin KeyboardEvents on Game { | ||||
|   void onKeyEvent(RawKeyEvent event); | ||||
| } | ||||
| @ -4,8 +4,6 @@ import 'package:meta/meta.dart'; | ||||
| 
 | ||||
| import 'processors.dart'; | ||||
| 
 | ||||
| export 'processors.dart'; | ||||
| 
 | ||||
| abstract class Layer { | ||||
|   List<LayerProcessor> preProcessors = []; | ||||
|   List<LayerProcessor> postProcessors = []; | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user
	 Renan
					Renan