-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Actor updates are being called more than once per frame #643
Comments
@excaliburjs/core-contributers thoughts? I will mark as a bug if you think it makes sense. |
Seems like a bug, go for it On Wed, Aug 31, 2016, 20:25 Kamran Ayub notifications@github.com wrote:
|
Found it:
It is running actor update multiple times per frame, thus multiple trait updates. |
<!-- If you're closing an issue with this pull request, or contributing a significant change, please include your changes in the appropriate section of CHANGELOG.md as outlined in CONTRIBUTING.md--> Closes #643 Pointer events were being triggered multiple times per frame. This was a result of the physics doing multiple passes on each actor by calling the update function multiple times. ## Proposed Changes: This fixes the issue by refactoring the integration step of actor update out of actor update, so that it can be called multiple times for collision passes and not affect other operations that expect update to be called once per frame. Additionally, this uncovered a bug in Actor.on('pointerup') opt-in which was subsequently fixed.
Context
I noticed while doing some audio testing (/tests/audio) that when I clicked the red square, the sound actually ended up playing 5 times all at once.
When I stepped through, it's because when we capture pointer events, each browser pointer event is captured in an array during a frame (the array is cleared at the end of a frame).
So, even a single "click" can generate n pointer events during a single frame.
Is this expected? It means people need to have guards in their event handlers to compensate for being called multiple times in a single frame.
Keep in mind: there could be a case where if you are using multi-touch you could trigger pointer events in multiple locations on the same frame--this is where it may make sense to keep an array.
Proposal
I propose only emitting a single
pointerup
,pointercancel
andpointerdown
event per actor during a frame (first valid pointer event wins). I would leavepointermove
to allow multiple per frame.This means, the logic would go:
The text was updated successfully, but these errors were encountered: