1- var GetTransformedPoint = require ( './GetTransformedPoint' ) ;
21var PointWithinHitArea = require ( './PointWithinHitArea' ) ;
2+ var TransformXY = require ( '../../../math/TransformXY' ) ;
33
44// Will always return an array.
55// Array contains matching Interactive Objects.
66// Array will be empty if no objects were matched.
77
8- var HitTest = function ( tempMatrix , x , y , gameObjects , camera , output )
8+ // x/y = pointer x/y (un-translated)
9+
10+ var HitTest = function ( tempPoint , x , y , gameObjects , camera , output )
911{
1012 var cameraW = camera . width ;
1113 var cameraH = camera . height ;
@@ -17,9 +19,13 @@ var HitTest = function (tempMatrix, x, y, gameObjects, camera, output)
1719 return output ;
1820 }
1921
20- var screenPoint = camera . getWorldPoint ( { x : x , y : y } ) ;
22+ // Stores the world point inside of tempPoint
23+ camera . getWorldPoint ( x , y , tempPoint ) ;
24+
2125 var culledGameObjects = camera . cull ( gameObjects ) ;
2226
27+ var point = { x : 0 , y : 0 } ;
28+
2329 for ( var i = 0 ; i < culledGameObjects . length ; i ++ )
2430 {
2531 var gameObject = culledGameObjects [ i ] ;
@@ -29,23 +35,12 @@ var HitTest = function (tempMatrix, x, y, gameObjects, camera, output)
2935 continue ;
3036 }
3137
32- tempMatrix . applyITRS ( gameObject . x , gameObject . y , - gameObject . rotation , gameObject . scaleX , gameObject . scaleY ) ;
33-
34- tempMatrix . invert ( ) ;
38+ var px = tempPoint . x + ( camera . scrollX * gameObject . scrollFactorX ) - camera . scrollX ;
39+ var py = tempPoint . y + ( camera . scrollY * gameObject . scrollFactorY ) - camera . scrollY ;
3540
36- var point = tempMatrix . transformPoint (
37- screenPoint . x + camera . scrollX * gameObject . scrollFactorX ,
38- screenPoint . y + camera . scrollY * gameObject . scrollFactorY
39- ) ;
41+ TransformXY ( px , py , gameObject . x , gameObject . y , gameObject . rotation , gameObject . scaleX , gameObject . scaleY , point ) ;
4042
41- // var point = GetTransformedPoint(
42- // tempMatrix,
43- // gameObject,
44- // screenPoint.x + camera.scrollX * gameObject.scrollFactorX,
45- // screenPoint.y + camera.scrollY * gameObject.scrollFactorY
46- // );
47-
48- if ( PointWithinHitArea ( gameObject , point . x , point . y , camera ) )
43+ if ( PointWithinHitArea ( gameObject , point . x , point . y ) )
4944 {
5045 output . push ( gameObject ) ;
5146 }
0 commit comments