@@ -43,6 +43,8 @@ var GlobalInputManager = new Class({
4343
4444 this . scale = { x : 1 , y : 1 } ;
4545
46+ this . bounds ;
47+
4648 this . _tempMatrix = new TransformMatrix ( ) ;
4749 this . _tempPoint = { x : 0 , y : 0 } ;
4850 this . _tempHitTest = [ ] ;
@@ -56,12 +58,31 @@ var GlobalInputManager = new Class({
5658 {
5759 this . canvas = this . game . canvas ;
5860
61+ this . updateBounds ( ) ;
62+
5963 this . keyboard . boot ( ) ;
6064 this . mouse . boot ( ) ;
6165 this . touch . boot ( ) ;
6266 this . gamepad . boot ( ) ;
6367 } ,
6468
69+ updateBounds : function ( )
70+ {
71+ var bounds = this . canvas . getBoundingClientRect ( ) ;
72+
73+ if ( window . scrollX )
74+ {
75+ bounds . left += window . scrollX ;
76+ }
77+
78+ if ( window . scrollY )
79+ {
80+ bounds . top += window . scrollY ;
81+ }
82+
83+ this . bounds = bounds ;
84+ } ,
85+
6586 update : function ( time , delta )
6687 {
6788 this . keyboard . update ( ) ;
@@ -79,8 +100,10 @@ var GlobalInputManager = new Class({
79100 return ;
80101 }
81102
82- this . scale . x = this . game . config . width / this . canvas . offsetWidth ;
83- this . scale . y = this . game . config . height / this . canvas . offsetHeight ;
103+ this . updateBounds ( ) ;
104+
105+ this . scale . x = this . game . config . width / this . bounds . width ;
106+ this . scale . y = this . game . config . height / this . bounds . height ;
84107
85108 // Clears the queue array, and also means we don't work on array data that could potentially
86109 // be modified during the processing phase
@@ -158,32 +181,32 @@ var GlobalInputManager = new Class({
158181
159182 transformX : function ( pageX )
160183 {
161- return ( pageX - this . canvas . offsetLeft ) * this . scale . x ;
184+ return ( pageX - this . bounds . left ) * this . scale . x ;
162185 } ,
163186
164187 transformY : function ( pageY )
165188 {
166- return ( pageY - this . canvas . offsetTop ) * this . scale . y ;
189+ return ( pageY - this . bounds . top ) * this . scale . y ;
167190 } ,
168191
169192 getOffsetX : function ( )
170193 {
171- return this . canvas . offsetLeft ;
194+ return this . bounds . left ;
172195 } ,
173196
174197 getOffsetY : function ( )
175198 {
176- return this . canvas . offsetTop ;
199+ return this . bounds . top ;
177200 } ,
178201
179202 getScaleX : function ( )
180203 {
181- return this . game . config . width / this . canvas . offsetWidth ;
204+ return this . game . config . width / this . bounds . width ;
182205 } ,
183206
184207 getScaleY : function ( )
185208 {
186- return this . game . config . height / this . canvas . offsetHeight ;
209+ return this . game . config . height / this . bounds . height ;
187210 }
188211
189212} ) ;
0 commit comments