Skip to content

feat: add pause, unpause, show, hide events & hook it into broadphase#1041

Open
dragoncoder047 wants to merge 15 commits into
kaplayjs:masterfrom
dragoncoder047:pauseunpauseevents
Open

feat: add pause, unpause, show, hide events & hook it into broadphase#1041
dragoncoder047 wants to merge 15 commits into
kaplayjs:masterfrom
dragoncoder047:pauseunpauseevents

Conversation

@dragoncoder047

Copy link
Copy Markdown
Contributor

Please describe what issue(s) this PR fixes.

closes #844 mostly.

  • Adds onPause, onUnpause, onHide, onUnhide
  • renames onResize for good measure too
  • hooks the broadphase to add and remove objects when they're paused or unpaused, rather than just always skipping them (the performance impact should be negligible since it's just strange to be spam unpausing and repausing objects every frame)

Summary

  • Changeloged

@imaginarny

Copy link
Copy Markdown
Member

Isn't the resize observer observing canvas? So if you have own canvas with dimensions set on page, it wouldn't trigger onTabResize even if window is resized until the canvas itself gets resized as well - which would be then misleading. Shouldn't it be kept as onResize then?

By default canvas is set to window viewport dimensions and is mostly used like that, but it's not the only way, if true.

Comment thread CHANGELOG.md

### Added

- The `onHide` and `onShow` global handlers (which have been deprecated for a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still should be marked as a breaking change, so add (!) in front

- - The `onHide` and `onShow` global handlers...
+ - **(!)** The `onHide` and `onShow` global handlers...

@imaginarny

Copy link
Copy Markdown
Member

And would also remove the broadphase hooking since it's possible of ending up hurting the perf, or at least it's uncertain. I confirmed it with MF as well. Offscreen with sidescrollers might be a good example when paused/unpaused is triggered on and off a lot. Adding/removing for some broadphase algos can be in particular more expensive (inserting in all overlapping grid square or correct branch in quadtree).

With skipping we at least know what we are at now, no uncertainty after. So unless we do proper testing of it behaving in more situations across broadphase algos, I would rather remove for now. You can always revisit later, to not block the events feature itself. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: onPause and onUnpause events

2 participants