Skip to content
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

Stage.offset may become inaccurate after DOM manipulation #285

Open
BenjaminDRichards opened this issue Feb 10, 2017 · 0 comments
Open

Stage.offset may become inaccurate after DOM manipulation #285

BenjaminDRichards opened this issue Feb 10, 2017 · 0 comments

Comments

@BenjaminDRichards
Copy link
Contributor

If a KiwiJS game is embedded in a document, and its position on the page shifts around without a window resize, then Stage.offset fails to update. This will result in inaccurate pointer input coordinates.

Unfortunately, from discussion on Stack Overflow, it seems there isn't a standard for detecting div resize events yet. There are some alternatives, but many rely on timers/RAFs and could be moderately heavy.

My intuition says there might be an optimal solution. We could use a "dirty" mark. Say we tag the offset as dirty at the start of each frame; and we cache the parameters used to create the offset. Then, when we access the offset, if it is dirty, and if the parameters have changed, we recalculate it, then mark it as clean. This will require a minimum of one extra boolean assignation per frame, a fixed cost increase, and a maximum of running the offset calculation once per frame, plus a boolean check every time offset is accessed.

It's probably worthwhile, as this will improve reliability on the web.

The alternative is to recommend that users call Stage.offset = Stage.getOffsetPoint( blah ) every time they manipulate the DOM, and that could rapidly get messy.

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

No branches or pull requests

1 participant