57 Commits

Author SHA1 Message Date
0fd2662d4b refactor!: Replace Offset with opacityFrom and opacityTo in ColorEffect (#2876)
`ColorEffect`'s API was a bit confusing because it used `Offset` for
getting values of opacity start and end from user. This PR changes that
to use optional `opacityFrom` and `opacityTo` double parameters. It also
adds validate checks on these value to make sure that are between 0 and
1.
2023-11-27 14:21:18 +01:00
5b67b8f14a fix: Remove deprecations for 1.10.0 (#2809)
Removed deprecations for 1.10.0 and fixes some small unreleased regressions found when going through the examples.
2023-10-11 15:57:25 +02:00
152fbb61db docs: Fix examples for v1.9.0 (#2757)
Fixed up some examples that needed fixing before releasing v1.9.0
2023-09-21 19:24:40 +00:00
9c1e1c3098 chore: Remove deprecations for v1.9.0 (#2749)
Removes everything that was marked as deprecated and that should be
removed for v1.9.0.
2023-09-19 16:47:41 +02:00
7c2f400076 feat!: Add CameraComponent to FlameGame (#2740)
This PR adds the `CameraComponent` and a `World` by default to the
FlameGame.
2023-09-18 21:06:37 +02:00
2d45d2be39 chore: Remove 1.8.0 deprecations (#2538)
Removes all the deprecated methods before 1.8.0 release.
2023-05-22 19:01:55 +02:00
87b8a067f3 refactor!: Move CameraComponent and events out of experimental (#2505)
This moves the CameraComponent and the new event system out of experimental since this now is the recommended way of handling things.
2023-04-19 09:55:32 +02:00
89926227c5 feat: Accept CollisionType in hitbox constructor (#2509)
With this PR we accept the `CollisionType` directly in the constructor.
2023-04-18 13:57:16 +00:00
dbda37b81a refactor: Add new lint rules (#2477)
This PR adds the following lint rules to our list:

```
always_put_required_named_parameters_first
avoid_multiple_declarations_per_line
avoid_positional_boolean_parameters
avoid_returning_null_for_void
avoid_returning_this
avoid_unnecessary_containers
enable_null_safety
library_private_types_in_public_api
no_leading_underscores_for_library_prefixes
no_leading_underscores_for_local_identifiers
prefer_null_aware_method_calls
tighten_type_of_initializing_formals
unnecessary_late
use_setters_to_change_properties
```

And these rules were considered, and some changes were made according to
them as a clean-up, but in many places they didn't make sense
(`prefer_asserts_with_message` I would have included, but there were too
many places that needed to be changes):

```
collection_methods_unrelated_type
prefer_asserts_with_message
avoid_renaming_method_parameters
```
2023-04-13 19:42:00 +00:00
de630a1c3a feat: Add isDragged in DragCallbacks mixin (#2472)
Adding a isDragged state for DragCallbacks mixin. This was available in the Draggable mixin.
2023-04-07 13:39:28 +02:00
b5bdf4ec17 feat!: The HasTappableComponents mixin is no longer needed (#2450)
This PR is the second in a series of refactors that aim to simplify event handling in Flame. The approach is as follows:

    Added the MultiTapDispatcher component, which contains the logic that used to be within the HasTappableComponents mixin. This component is internal; it mounts to a FlameGame directly, and ensures that it is a singleton.
    Whenever any TapCallbacks component is added to a game, it automatically adds the MultiTapDispatcher component (unless there is already one), which in turn registers a tap gesture detector with GestureDetectorBuilder and rebuilds the game widget.

The end result is that now in order to make a component tappable you only need to add the TapCallbacks mixin to that component, everything else will be handled by the framework.

Consequently, the HasTappableComponents mixin is now empty and marked as deprecated.
2023-04-02 16:52:57 +00:00
637c258b25 feat: Change HasCollisionDetection to be on Component (#2404)
This change makes it possible to have the collision detection system further down in the tree than on the FlameGame, this enables you to have collision detection on the World component for example.
Today it doesn't work if you have several worlds where the components are overlapping across the worlds, since the hitboxes live on top level.

So now you can use a World like this:

class CollisionDetectionWorld extends World with HasCollisionDetection {}
and all hitboxes added in there will only react with other hitboxes added to that world.
2023-03-15 13:11:23 +01:00
d898b539f7 refactor!: The method onLoad() now returns FutureOr<void> (#2228)
Before this PR, the return type of onLoad() was Future<void>?, after this PR the return type is FutureOr<void> -- both for classes Component and Game.

Reasons:

The use of FutureOr is more idiomatic in Dart, this class was specifically created in order to be used in situations like ours.
This makes learning Flame easier for beginners, since you no longer need to explain what asynchronous programming is from the start (and onLoad() is one of the first methods the user encounters in Flame).
The code can be cleaner in case when onLoad doesn't need to be async.
With new approach, the onLoad() method can be overridden as either

@override
Future<void> onLoad() async { ... }
or

@override
void onLoad() { ... }
Of course, it can also be overridden as

@override
FutureOr<void> onLoad() { ... }
but this is rare, only for components that are designed to be further subclassed, or for mixins.

The documentation was updated to show the new recommended usage.
2022-12-23 20:30:40 +00:00
cbfa789e75 chore: Fix some spelling mistakes (#2148)
Fix all* typos reported by CSpell, and add some more words into the dictionaries.

(Except for two in the flame_isolate/example package).
2022-11-06 14:06:44 +00:00
9e6bf4fbcc feat: Add paint layers to HasPaint and associated component renders (#2073) 2022-10-24 22:37:24 +00:00
6b78b10fb3 feat: Add optional maxDistance to raycast (#2012)
This PR adds an optional parameter to raycast API called maxDistance. Using this parameter users can control the limit within which raycast scans for hits.
2022-10-07 14:13:42 +02:00
475b226911 docs: Fixed broken example links (#2030) 2022-10-06 10:15:32 +02:00
e33d5410a3 feat: quad tree broadphase support (#1894)
Quad tree broadphase support.
2022-09-27 13:53:27 +02:00
b1a6dd18f2 docs: Added bouncing ball example in collision_detection examples and updated flame_forge2d to latest (#1868)
This PR adds two updates.

It updates the flame_forge2d to latest version i.e on pub.dev in examples and padracing projects.

Adds a bouncing ball example in the collision detection examples demonstrating a simple example of collision and bouncing of a ball from the walls around it.
2022-08-29 09:34:33 +00:00
ed452dd172 feat!: Raycasting and raytracing (#1785)
This PR implements raytracing and raycasting for the built-in hitboxes.

If you pass in your own collision detection system to the HasCollisionDetection mixin you have to change the signature of that to: CollisionDetection<ShapeHitbox>instead of CollisionDetection<Hitbox>.
2022-08-19 22:44:18 +02:00
2a41d0d683 feat: Move to Flutter 3.0.0 and Dart 2.17.0 (#1713)
This upgrades all packages to Flutter 3.0.0 and fixes all analyze issues that came from that.
2022-06-08 06:04:40 +00:00
843ddc3624 refactor: Move to package imports (#1625)
* refactor: Move to package imports

* Fix local imports

* Removed unused imports
2022-05-15 15:04:35 +00:00
4c68c2b0a2 feat: Add FpsComponent and FpsTextComponent (#1595) 2022-05-11 19:49:14 +02:00
6dd0a970e6 docs: Move flame_forge2d examples to main examples (#1588) 2022-05-01 13:00:48 +00:00
e894d20133 fix: debugMode should be inherited from parent when mounted (#1469) 2022-03-19 16:13:50 +01:00
dfeafdd6f3 fix: Fix collision detection comments and typo (#1422)
* Fix collision detection comments and typo

* Update packages/flame/lib/src/collisions/collision_callbacks.dart

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Update doc/flame/collision_detection.md

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2022-03-08 14:38:21 +01:00
29dd09ca92 feat(collision detection)!: Use a broadphase to make collision detection more efficient (#1252) 2022-03-07 09:08:32 +01:00
05f7a4c3d6 refactor: Remove Loadable, optional onLoads (#1333) 2022-01-24 23:23:12 +01:00
27adda17b7 fix!: Remove pointerId from Draggable callbacks (#1313)
Since pointerId is already handled by the handle* methods we don't have to expose it in the onDrag* methods, this conforms with the standard set in Tappable.
2022-01-18 23:22:10 +01:00
5c47d7f6d7 chore: analyze issues introduced from new dart version (#1196)
* Added Component.childrenFactory

* fix some of the lint warnings

* more lint warnings

* remove changelog entry

* more analyzer warnings

* one more warning

* one more warning

* remove more unused imports

* fix more warnings

* another warning

* one more warning

* a lot more warnings

* some more warnings

* fix warnings in flame_svg

* fix warnings in flame_bloc

* Remove OrderedSet override feature

* Remove testRandom change

* Remove unnecessary type checks

* Re-remove deprecated argument in random_test

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2021-12-09 15:40:43 +01:00
c35fb46078 Fix hitbox circle on flip (#1165) 2021-12-05 20:38:52 +01:00
bfcda073bb Effect controllers restructuring (#1134)
* Update effectController

* move effect controllers into the controllers/ directory

* Add .forward property to EffectController

* SimpleEffectController supports reverse time

* Fixing some compile errors

* rename SimpleEffectController -> LinearEffectController

* minor cleanup

* DurationEffectController and PauseEffectController

* ReverseLinearEffectController

* CurvedEffectController and its reverse

* InfiniteEffectController

* Added EffectController.recede()

* Add EffectController.update()

* Add InfiniteEffectController'

* RepeatedEffectController

* SequenceEffectController

* DelayedEffectController

* Restore the [EffectController.started] property

* minor

* Rename reset() -> setToStart()

* time direction is now managed from the Effect class

* StandardEffectController replaced with function standardController()

* update some doc-comments

* flutter analyze

* flutter format

* fix some tests

* more test fixes

* fix remaining tests

* format

* rename local variable

* minor simplification

* Expand docs in PauseEffectController

* added tests

* Curved controller test

* fix errors

* formatting

* added more tests

* format

* fix RepeatedEffectController

* more tests

* format

* changelog

* increase tolerance

* Replaced standardController with factory EffectController constructor

* Added parameter EffectController({alternate=false})

* Added default for curve= parameter

* rename

* rename tests

* added more exports

* rename tests

* rename src/effects2

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2021-12-04 15:58:42 +00:00
790b8f73dd Remove old effects system (#1157)
* Remove old effects system

* Add changelog entry
2021-12-03 15:02:25 +01:00
fe162c6d90 Introduce updateTree (#1158)
* Introduce updateTree

* Update tests

* Fix update for game-in-game situations

* Add dartdoc to updateTree
2021-12-03 14:01:46 +01:00
8b132d7c0b Unify examples structure (#1118)
* Animations, CameraAndViewport, CollisionDetection and Components unified

* Added descriptions to effects

* Rename input games

* Unify input stories

* Add info to parallax section

* Added descriptions to the rendering examples

* Add descriptions to the sprites directory

* Fix utils and rendering section

* Add descriptions to the widgets section

* Delete directory that rebase brought back

* Unify game names

* Added some styleguide docs for examples

* Fix analyze issues

* All files should have _example as suffix

* Made the FollowComponentExample a bit easier to understand

* Change priority of ember
2021-11-19 14:28:04 +01:00
03128170bd Add some new lint rules (#1117) 2021-11-18 15:35:10 +00:00
795264edbf Unify mixin names (#1114) 2021-11-18 08:48:31 +01:00
3cb23ef530 TextPaint to use TextStyle instead of TextPaintConfig (#1086)
* `TextPaint` to use `TextStyle` instead of `TextPaintConfig`

* Update packages/flame/lib/src/text.dart

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Removed BaseTextConfig and TextPaintConfig

* Update text docs

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Remove generics

* Update TextBoxExample

* Update text examples variable names

* Fix TextPaint in collision_detection example

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
2021-11-13 16:38:06 +01:00
cd7a0bbb65 ShapeComponent and Hitbox to take transform of parents full ancestor tree into consideration (#1076)
* `ShapeComponent` changes size, position and angle of underlying Shape

* Added description to ShapeComponent

* Fix test

* Update packages/flame/lib/src/components/shape_component.dart

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Add absoluteScale and absoluteAngle to PositionComponent

* Refactor ShapeComponent

* Should be scaled by total scale, not scaled size

* Premature optimization for creation for objects in Polygon

* Use path for default Polygon constructor

* Do not sync component and hitbox shape

* Fix analyze issue

* Add example for flipping with collision detection

* Don't use absoluteScale

* Fix examples

* Fix examples

* Doesn't need super.render

* Fix Circle dartdoc

* Update changelog

* Update names of vertices caches in Polygon

* Update text docs

* Revert "Update text docs"

This reverts commit 73a68a465d76eb0eb50bb3753e57b2f4e3b5a7f4.

* Fix examples

* ShapeComponents docs

* Move example games to the top

* Fix dartdoc comment about polygon vertex relation

* Fix order of polygon vertices in dartdoc

* Fix anchor for PolygonComponent.fromPoints

* Add test with ancestors

* Update doc/components.md

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Update doc/components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Rename example classes

* Fix linting issues in examples

* Don't use px

* Use isTrue and isFalse

* Update doc/components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Fixed comments on PR

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2021-11-13 16:00:24 +01:00
d53ac50859 Add flame_lint to examples (#1090) 2021-11-12 10:35:56 +01:00
0a7b87e202 Remove unnecessary super.render calls (#1084)
* Remove unnecessary super.render calls

* Update tutorial and docs
2021-11-11 11:50:01 +01:00
b7a2d3fdf8 Simplified the usage of ShapeComponent (#1068)
* Simplified the usage of ShapeComponent

* Default constructor for _RandomCircle

* Use default constructor

* Forced Anchor.center on ShapeComponent

* Fix examples using SquareComponent

* Removed unnecesary import

* Renamed edgeLength to size
2021-11-03 14:30:58 +01:00
3a8abe139b Rename Hitbox mixin to HasHitboxes (#1060) 2021-11-02 12:44:21 +01:00
55ab428a9e Collision detection between children (#943)
* Enable children of different components to collide

* Re-add import
2021-09-15 15:11:00 +02:00
a1b6ffa04a Game as a Component (#906)
* Game as a component

* Fix component stories

* Effects are now components

* Update effects docs

* Handle swap of parent

* Fix reAddChildren

* Wait for children to be added

* BaseComponent and PositionComponent to be non-abstract

* Simplify HasGameRef

* Revert so that onLoad can be null

* Fix example description

* Effects as components

* Remove gameRef from addChildren

* Fix hasGameRef

* Start migrating effects

* Updated comments of effect fields

* Fix comments

* Continue to fix sequence and combined effects

* Upgrade ordered_set

* Fix position_component_test

* BaseComponent -> Component

* Fix combined and sequence effects

* Await components to be added in tests

* Remove unnecessary game.update in tests

* Fix some tests related to composition

* BaseGame should be used in examples

* Fix CombinedEffect test

* Keyboard code to be based on Component

* Fix keyboard tests

* Fix analyze problems

* Fix sequence_effect

* Fix combined_effect_test

* Store peak state instead of end state

* Fix sequence_effect tests

* Update tutorial

* Fix tutorial 1

* Remove SimplePositionComponentEffect

* Remove unused test variable

* Update docs

* Removed onMount

* Remove onMount

* Add missing dartdoc

* Fix dart docs

* Add super.update where needed

* Move reAddChildren to component

* Reorganize method order in game widget

* preOffset -> initialDelay, postOffset -> peakDelay

* Introduce component.onParentChange

* Remove tests in wrong file

* Fix composed component test

* Add game lifecycle test

* Use BaseGame for mouse cursor test

* Oxygen should (?) not call super.update

* Use BaseGame in keyboard_test

* Fix onLoad to be properly cached

* Re-add unintentionally removed override

* Fix info for collision detection tests

* Add test for correct lifecycle on parent change

* Fix particles example

* Add component lifecycle diagram to the docs

* Add docs for the game lifecycle

* onRemove should be called when a game is removed from the widget

* Fix analyze errors

* prepare should be called from the component itself, not its parent

* Fix dartdoc

* onParentChange -> onMount

* onMount should have void as return type

* Simplify the loaderFuture in GameWidget

* Fix mock_canvas

* Fix rebase problem

* Remove asComponent

* Less complex _loaderFuture

* Add super.update to no_fcs parallax example

* Fix async tests

* Revert _loaderFuture

* Fix analyze issues

* await gameWithCollidables

* Keep epsilon small where it can be

* tappable methods should return bool

* Game lifecycle is now the same as for Component

* Remove mustCallSuper from component.update

* Make onLoadCache protected

* @internal on onLoadCache

* Cache/Memoize debugPaint and debugTextPaint

* Fix imports

* Fix comments

* Always call super.onLoad so that mixins can override it

* Add forgotten super.onLoad

* Bump coverage percentage

* HasCollidables should override update

* Fix Game comments

* Fix some dartdoc

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Game + Loadable as mixins

* Update packages/flame/lib/src/game/game_widget/game_widget.dart

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Update loadable docs

* Fix comments

* Move fps_counter

* Fix keyboard example

* Fix dartdoc

* Remove tutorials temporarily

* Fix game lowlevel graph

* Fix resize issue

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Luan Nico <luanpotter27@gmail.com>
2021-09-15 00:17:49 +02:00
53fe9e8238 Remove FPSCounter from BaseGame (#913) 2021-08-10 22:00:52 +02:00
54fbd260bc Scale for PositionComponent (#892)
* Draft of PositionComponent.scale

* Use matrix transformations

* Update tests to take matrix transform into consideration

* Add tests for collision detection with scale

* Rename ScaleEffect to SizeEffect

* Use transform matrix to prepare canvas

* Fix scaledSizeCache

* Add changelog entries and docs

* Dartdoc on public access methods

* Update packages/flame/CHANGELOG.md

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>

* Move cache classes to own directory

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
2021-08-06 21:59:52 +02:00
e3f9f1a469 addShape -> addHitbox (#882) 2021-07-26 20:19:45 +02:00
64a40ff641 Refactor joystick (#876)
* Refactor joystick

* Fix directional tests

* Joystick example

* Any PositionComponent can be used as knob and background

* Add MarginButtonComponent

* Fix JoystickExample

* Update joystick docs

* Fix joystick direction tests

* Fix effect tests

* Fix analyze issue

* Update docs

* Update docs

* Move joystick to input export

* Update packages/flame/lib/src/geometry/shape.dart

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Add test and description for screenAngle

* Update examples/lib/stories/controls/joystick_player.dart

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Update doc/input.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* controls -> input in examples to align with export file

* controls -> input

* Add simple joystick example

* Fix imports

* velocity -> relativeDelta

Co-authored-by: Luan Nico <luanpotter27@gmail.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
2021-07-15 12:00:41 +02:00
1e79a42161 Rename Tapable to Tappable (#868) 2021-07-07 10:48:58 +02:00