-
Notifications
You must be signed in to change notification settings - Fork 312
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
touchevent objects not responding after window resize #324
Comments
The underlying issue seems clear upon a quick code review. Touch/mouse events are relying on I am no expert in web development, so my knowledge is definitely lacking in areas; however, I have to wonder: why are absolute coordinates being used in the first place? If it is possible to obtain coordinates relative to the stage element from the original touch/mouse events, then no coordinate conversion would be needed. This would probably be a good line of investigation, unfortunately I do not have any more time to devote beyond this post. Provided page-centric coordinates must be used, one possible fix involves monitoring the stage element for changes in positioning, to allow the Until the best course of action is determined and implemented, it should be easy enough to work around the issue. When you detect the position of the stage element has changed, manually recompute the values within the if (enchant.Core.instance) {
var core = enchant.Core.instance;
var bounding = core._element.getBoundingClientRect();
core._pageX = Math.round(window.scrollX || window.pageXOffset + bounding.left);
core._pageY = Math.round(window.scrollY || window.pageYOffset + bounding.top);
} If it is not practical to monitor the stage element, you instead could replace the if (enchant.Core.instance) {
console.log("enchant.js detected. Patching Event._initPosition to workaround issue #324.");
enchant.Event.prototype._initPosition = function(pageX, pageY) {
var core = enchant.Core.instance;
var bounding = core._element.getBoundingClientRect();
var stageX = Math.round(window.scrollX || window.pageXOffset + bounding.left);
var stageY = Math.round(window.scrollY || window.pageYOffset + bounding.top);
this.x = this.localX = (pageX - stageX) / core.scale;
this.y = this.localY = (pageY - stageY) / core.scale;
};
} NOTE: I have done only minimal testing of these snippets, so do take care to test them carefully to ensure they function well in your environment. |
Thank you for your work @seraku24 |
If there's an obvious fix I'm missing then feel free to disregard, but it appears items designed to be clicked on in an Enchant game no longer respond when a window is resized. Returning the window back to the original size returns functionality, but there doesn't seem to be a way to reposition the touch-area for objects with a command like window.onresize.
The text was updated successfully, but these errors were encountered: