From 550e53b81b1610612e19a8fefbfcc032a9dbf5c2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 28 Feb 2018 14:27:28 +0000 Subject: [PATCH] Fixed `InputManager.updateBounds` so it factors in the document element position. Also added `InputManager.resize` method, as the scale wouldn't ever be updated in the update loop if no interactive objects exist. --- src/input/InputManager.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/input/InputManager.js b/src/input/InputManager.js index 2bb86a805..8670e09bc 100644 --- a/src/input/InputManager.js +++ b/src/input/InputManager.js @@ -227,15 +227,39 @@ var InputManager = new Class({ */ updateBounds: function () { - var clientRect = this.canvas.getBoundingClientRect(); var bounds = this.bounds; - bounds.left = clientRect.left + window.pageXOffset; - bounds.top = clientRect.top + window.pageYOffset; + var clientRect = this.canvas.getBoundingClientRect(); + + bounds.x = clientRect.left + window.pageXOffset - document.documentElement.clientLeft; + bounds.y = clientRect.top + window.pageYOffset - document.documentElement.clientTop; bounds.width = clientRect.width; bounds.height = clientRect.height; }, + /** + * [description] + * + * @method Phaser.Input.InputManager#resize + * @since 3.2.0 + */ + resize: function () + { + this.updateBounds(); + + // Game config size + var gw = this.game.config.width; + var gh = this.game.config.height; + + // Actual canvas size + var bw = this.bounds.width; + var bh = this.bounds.height; + + // Scale factor + this.scale.x = gw / bw; + this.scale.y = gh / bh; + }, + /** * [description] *