-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add scaling gesture for components #3770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@stilnat did you see this from DCM? |
|
yeah working on fixing the few linting error left |
spydon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just two small comments and docs are missing, the docs live under the doc directory in the root.
packages/flame/lib/src/events/component_mixins/scale_callbacks.dart
Outdated
Show resolved
Hide resolved
packages/flame/lib/src/events/flame_game_mixins/scale_dispatcher.dart
Outdated
Show resolved
Hide resolved
spydon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm! Just some minor nits.
Thanks for your contribution.
| super.update(dt); | ||
|
|
||
| if (addCameraRotation) { | ||
| camera.viewfinder.angle += 0.001; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two should be dependent on dt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: Lukas Klingsbo <[email protected]>
Co-authored-by: Lukas Klingsbo <[email protected]>
… scale-gesture
Description
Currently, scaling is only working on device scale. This PR allows scaling gesture to be applied on components, very much like dragging works with drag callbacks. I added a ScaleDispatcher component which works very similarly to MultiDragDispatcher, basically sending the callbacks of ScaleGestureRecognizer to the components.
There was some tricky parts though. The goal was to preserve multi drag functionality while adding scale functionality but I run into this issue :
When running concurrently ScaleGestureRecognizer and ImmediateMultiDragGestureRecognizer, since drag in a simpler gesture it is usually recognized before scale, and therefore, drag wins the gesture arena and one pointer (finger) gets reserved for dragging. Scale gets recognized a bit later, but with a single pointer, and data such as scale or rotation are meaningless with a single pointer.
More generally, multi dragging and scaling are two very similar gestures and it will inevitably lead to some ambiguities.
There was multiple solutions to this, all with their own drawbacks :
but quite limiting.
We decided to go with the third solution as it preserves the ability to do multi drag instantaneously while allowing scaling at the same time. One issue inherent to this solution is also linked to the ambiguity between some multi drag gestures and scaling, preventing some multi drag gestures to be performed properly (basically all multi drag gestures similar to scaling).
One possibility would be to use the data from the single pointer scaling and send that to MultiDragDispatcher, basically what solution 3 does but the other way around. this would allow for drag and scaling to work at the same time.
Another issue exists that might be fixable though : it doesn't behave great when three fingers are involved, basically when I lift one of the two first fingers, the third one is used in the scale and rotation computations leading to unwanted "jumps".
The issue is that pointers are not really tracked, so eventually the third finger position can be used as if it was the second one.
Future things to do after this PR
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Closes #3768