-
-
Notifications
You must be signed in to change notification settings - Fork 934
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
[idea] Convert HasTappableComponents/HasDraggableComponents into classes #1733
Comments
Sounds very good! One less step for the user to worry about. |
I am failing to see the practical difference, won't this be the same thing but instead of adding a mixin to the class, users would add an instance? |
Now they have to add two mixins, with this change only the component mixin will be necessary and that mixin will add the interface class automatically to the game when that component is added to the game. |
Alright, but will this work in runtime? Like if a component is added after the game has been mounted/attached? |
Yes, it would work just as with overlays: you add an An interesting corollary of this would be the possibility of building an example where you can turn on/off various detectors (ScaleDetector, PanDetector, etc) and see how they work together. Though this would probably not be useful for any real-world game. |
Interesting! I am all for that, I definitely think this could improve. I would just like to do some POCs before. What I am concerned about this is with the following scenario: No tapables components > adds one tapable component > screen flicks because of rebuilt. I know that this scenario can already happen with overlays, but components are added and removed way more often than overlays, so this this could be worse on this context. |
Hmm, that's a good point. My understanding of rendering in Flutter was like this (and perhaps @renancaraujo can fact check me on this one): Flutter renders the entire rendering object tree and saves it in the buffer; on the next frame, it rebuilds those objects that are marked as dirty (and Flame is always dirty), composes the screen buffer out of all the available pieces, and replaces the old screen buffer with the new one. Thus, the only way for a screen flick to occur is if there was at least one frame where we requested to draw a black screen. Now, I imagine this could potentially happen if you mount a new component that adds many other components but does not wait for them to load -- there may occur a frame when the component has only the black background and no children, which would look like a flicker. I presume it could be something like that with overlays too, if the overlay needs to load/add something, but it doesn't await for the loading to end. These considerations, though, wouldn't affect the proposed So, I don't think there would be any flicker there -- but of course we ought to have an experiment to see how this would work in practice. |
Me neither!
Exactly, I just want to for us to be sure before we move to a full blown implementation |
I wonder if there is an opportunity here for new possibilities like this:
Currently this wouldn't be possible because scale gestures interfere with the drag gestures (and to a lesser extent with the tap gestures as well). |
Yes! this is a great improvement of that system IMO. Because it will improve a lot possible conflicts of inputs. |
@st-pasha what is the status of this? Have you started working on a solution? |
@alestiago I haven't, this could probably wait until after the next release (which is in just a few days). |
This PR is first in a series of refactors that aim to simplify event handling in Flame. The approach is as follows: Added class GestureDetectorBuilder, which encapsulates the logic of applyGestureDetectors() in a class. This class resides within the Game and initiates widget rebuild whenever any new gesture detectors are added or removed. Note: [idea] Convert HasTappableComponents/HasDraggableComponents into classes #1733 suggests having a list of interfaces inside the Game class -- this is essentially that list, encapsulated in a class. Added the MultiDragDispatcher component, which contains the logic that used to be within the HasDraggableComponents mixin. This component is internal; it mounts to a FlameGame directly, and ensures that it is a singleton. Whenever any DragCallbacks component is added to a game, it automatically adds the MultiDragDispatcher component (unless there is already one), which in turn registers a drag gesture detector with GestureDetectorBuilder and rebuilds the game widget. The end result is that now in order to make a component draggable you only need to add the DragCallbacks mixin to that component, everything else will be handled by the framework. Consequently, the HasDraggableComponents mixin is now empty and marked as deprecated.
@st-pasha we should do the same with the Tap events until we release v1.7.0 right? |
I think we can close this since the callback mixins work without the game mixins now. |
What could be improved
Currently the
HasTappableComponents
andHasDraggableComponents
are mixins on theGame
class, but we could have them as regular objects added to the class, i.e:Then in the
GameWidget
, instead of checkingif (game is MultiTouchTapDetector)
, we'd have insteadif (game.hasInterface(MultiTouchTapDetector))
.Why should this be improved
This would provide the following benefits:
Game
class - instead theTapCallbacks
mixin can add the interface that it needs at runtime;HasTappableComponents
, but we cannot extend a mixin. This would make extending the events functionality much easier.Any risks?
We could do this change only to the new
HasTappableComponents
/HasDraggableComponents
mixins which are still in the experimental stage, so that wouldn't be that much breaking.The text was updated successfully, but these errors were encountered: