@@ -128,9 +128,12 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
128128 {
129129 return false ;
130130 }
131+
132+ var tilemapLayerOffsetX = ( ! tilemapLayer . fixedToCamera ? tilemapLayer . position . x : 0 ) ;
133+ var tilemapLayerOffsetY = ( ! tilemapLayer . fixedToCamera ? tilemapLayer . position . y : 0 ) ;
131134
132135 // We re-check for collision in case body was separated in a previous step
133- if ( ! tile . intersects ( ( body . position . x - tilemapLayer . position . x ) , ( body . position . y - tilemapLayer . position . y ) , ( body . right - tilemapLayer . position . x ) , ( body . bottom - tilemapLayer . position . y ) ) )
136+ if ( ! tile . intersects ( ( body . position . x - tilemapLayerOffsetX ) , ( body . position . y - tilemapLayerOffsetY ) , ( body . right - tilemapLayerOffsetX ) , ( body . bottom - tilemapLayerOffsetY ) ) )
134137 {
135138 // no collision so bail out (separated in a previous step)
136139 return false ;
@@ -181,8 +184,8 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
181184 if ( body . deltaX ( ) !== 0 && body . deltaY ( ) !== 0 && ( tile . faceLeft || tile . faceRight ) && ( tile . faceTop || tile . faceBottom ) )
182185 {
183186 // We only need do this if both axis have checking faces AND we're moving in both directions
184- minX = Math . min ( Math . abs ( ( body . position . x - tilemapLayer . position . x ) - tile . right ) , Math . abs ( ( body . right - tilemapLayer . position . x ) - tile . left ) ) ;
185- minY = Math . min ( Math . abs ( ( body . position . y - tilemapLayer . position . y ) - tile . bottom ) , Math . abs ( ( body . bottom - tilemapLayer . position . y ) - tile . top ) ) ;
187+ minX = Math . min ( Math . abs ( ( body . position . x - tilemapLayerOffsetX ) - tile . right ) , Math . abs ( ( body . right - tilemapLayerOffsetX ) - tile . left ) ) ;
188+ minY = Math . min ( Math . abs ( ( body . position . y - tilemapLayerOffsetY ) - tile . bottom ) , Math . abs ( ( body . bottom - tilemapLayerOffsetY ) - tile . top ) ) ;
186189 }
187190
188191 if ( minX < minY )
@@ -192,7 +195,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
192195 ox = this . tileCheckX ( body , tile , tilemapLayer ) ;
193196
194197 // That's horizontal done, check if we still intersects? If not then we can return now
195- if ( ox !== 0 && ! tile . intersects ( ( body . position . x - tilemapLayer . position . x ) , ( body . position . y - tilemapLayer . position . y ) , ( body . right - tilemapLayer . position . x ) , ( body . bottom - tilemapLayer . position . y ) ) )
198+ if ( ox !== 0 && ! tile . intersects ( ( body . position . x - tilemapLayerOffsetX ) , ( body . position . y - tilemapLayerOffsetY ) , ( body . right - tilemapLayerOffsetX ) , ( body . bottom - tilemapLayerOffsetY ) ) )
196199 {
197200 return true ;
198201 }
@@ -210,7 +213,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
210213 oy = this . tileCheckY ( body , tile , tilemapLayer ) ;
211214
212215 // That's vertical done, check if we still intersects? If not then we can return now
213- if ( oy !== 0 && ! tile . intersects ( ( body . position . x - tilemapLayer . position . x ) , ( body . position . y - tilemapLayer . position . y ) , ( body . right - tilemapLayer . position . x ) , ( body . bottom - tilemapLayer . position . y ) ) )
216+ if ( oy !== 0 && ! tile . intersects ( ( body . position . x - tilemapLayerOffsetX ) , ( body . position . y - tilemapLayerOffsetY ) , ( body . right - tilemapLayerOffsetX ) , ( body . bottom - tilemapLayerOffsetY ) ) )
214217 {
215218 return true ;
216219 }
@@ -239,13 +242,14 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
239242 tileCheckX : function ( body , tile , tilemapLayer ) {
240243
241244 var ox = 0 ;
245+ var tilemapLayerOffsetX = ( ! tilemapLayer . fixedToCamera ? tilemapLayer . position . x : 0 ) ;
242246
243247 if ( body . deltaX ( ) < 0 && ! body . blocked . left && tile . collideRight && body . checkCollision . left )
244248 {
245249 // Body is moving LEFT
246- if ( tile . faceRight && ( body . x - tilemapLayer . position . x ) < tile . right )
250+ if ( tile . faceRight && ( body . x - tilemapLayerOffsetX ) < tile . right )
247251 {
248- ox = ( body . x - tilemapLayer . position . x ) - tile . right ;
252+ ox = ( body . x - tilemapLayerOffsetX ) - tile . right ;
249253
250254 if ( ox < - this . TILE_BIAS )
251255 {
@@ -256,9 +260,9 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
256260 else if ( body . deltaX ( ) > 0 && ! body . blocked . right && tile . collideLeft && body . checkCollision . right )
257261 {
258262 // Body is moving RIGHT
259- if ( tile . faceLeft && ( body . right - tilemapLayer . position . x ) > tile . left )
263+ if ( tile . faceLeft && ( body . right - tilemapLayerOffsetX ) > tile . left )
260264 {
261- ox = ( body . right - tilemapLayer . position . x ) - tile . left ;
265+ ox = ( body . right - tilemapLayerOffsetX ) - tile . left ;
262266
263267 if ( ox > this . TILE_BIAS )
264268 {
@@ -296,13 +300,14 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
296300 tileCheckY : function ( body , tile , tilemapLayer ) {
297301
298302 var oy = 0 ;
303+ var tilemapLayerOffsetY = ( ! tilemapLayer . fixedToCamera ? tilemapLayer . position . y : 0 ) ;
299304
300305 if ( body . deltaY ( ) < 0 && ! body . blocked . up && tile . collideDown && body . checkCollision . up )
301306 {
302307 // Body is moving UP
303- if ( tile . faceBottom && ( body . y - tilemapLayer . position . y ) < tile . bottom )
308+ if ( tile . faceBottom && ( body . y - tilemapLayerOffsetY ) < tile . bottom )
304309 {
305- oy = ( body . y - tilemapLayer . position . y ) - tile . bottom ;
310+ oy = ( body . y - tilemapLayerOffsetY ) - tile . bottom ;
306311
307312 if ( oy < - this . TILE_BIAS )
308313 {
@@ -313,9 +318,9 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
313318 else if ( body . deltaY ( ) > 0 && ! body . blocked . down && tile . collideUp && body . checkCollision . down )
314319 {
315320 // Body is moving DOWN
316- if ( tile . faceTop && ( body . bottom - tilemapLayer . position . y ) > tile . top )
321+ if ( tile . faceTop && ( body . bottom - tilemapLayerOffsetY ) > tile . top )
317322 {
318- oy = ( body . bottom - tilemapLayer . position . y ) - tile . top ;
323+ oy = ( body . bottom - tilemapLayerOffsetY ) - tile . top ;
319324
320325 if ( oy > this . TILE_BIAS )
321326 {
0 commit comments