@@ -35,6 +35,15 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
3535 */
3636 this . map = tilemap ;
3737
38+ /**
39+ * A custom view.
40+ *
41+ * @property {Phaser.Point } view
42+ */
43+ this . view = game . camera ;
44+
45+ this . _camDetatched = false ;
46+
3847 /**
3948 * The index of this layer within the Tilemap.
4049 * @property {number } index
@@ -232,7 +241,7 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
232241 this . renderSettings . copyCanvas = Phaser . TilemapLayer . ensureSharedCopyCanvas ( ) ;
233242 }
234243
235- this . fixedToCamera = true ;
244+ // this.fixedToCamera = true;
236245
237246} ;
238247
@@ -280,6 +289,20 @@ Phaser.TilemapLayer.prototype.preUpdate = function() {
280289
281290} ;
282291
292+ Phaser . TilemapLayer . prototype . addCamera = function ( ) {
293+
294+ this . view = this . game . camera ;
295+ this . _camDetatched = true ;
296+
297+ } ;
298+
299+ Phaser . TilemapLayer . prototype . removeCamera = function ( x , y ) {
300+
301+ this . view = new Phaser . Point ( x , y ) ;
302+ this . _camDetatched = true ;
303+
304+ } ;
305+
283306/**
284307* Automatically called by World.postUpdate. Handles cache updates.
285308*
@@ -290,12 +313,12 @@ Phaser.TilemapLayer.prototype.postUpdate = function () {
290313
291314 if ( this . fixedToCamera )
292315 {
293- this . position . x = ( this . game . camera . view . x + this . cameraOffset . x ) / this . game . camera . scale . x ;
294- this . position . y = ( this . game . camera . view . y + this . cameraOffset . y ) / this . game . camera . scale . y ;
316+ // this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
317+ // this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
295318 }
296319
297- this . _scrollX = this . game . camera . view . x * this . scrollFactorX / this . scale . x ;
298- this . _scrollY = this . game . camera . view . y * this . scrollFactorY / this . scale . y ;
320+ this . scrollX = this . view . x * this . scrollFactorX / this . scale . x ;
321+ this . scrollY = this . view . y * this . scrollFactorY / this . scale . y ;
299322
300323} ;
301324
@@ -314,8 +337,8 @@ Phaser.TilemapLayer.prototype._renderCanvas = function (renderSession) {
314337 this . position . y = ( this . game . camera . view . y + this . cameraOffset . y ) / this . game . camera . scale . y ;
315338 }
316339
317- this . _scrollX = this . game . camera . view . x * this . scrollFactorX / this . scale . x ;
318- this . _scrollY = this . game . camera . view . y * this . scrollFactorY / this . scale . y ;
340+ this . scrollX = this . view . x * this . scrollFactorX / this . scale . x ;
341+ this . scrollY = this . view . y * this . scrollFactorY / this . scale . y ;
319342
320343 this . render ( ) ;
321344
@@ -977,7 +1000,7 @@ Phaser.TilemapLayer.prototype._fixX = function (x) {
9771000 x = 0 ;
9781001 }
9791002
980- if ( this . scrollFactorX === 1 )
1003+ if ( this . scrollFactorX === 1 && ! this . _camDetatched )
9811004 {
9821005 return x ;
9831006 }
@@ -996,7 +1019,7 @@ Phaser.TilemapLayer.prototype._fixX = function (x) {
9961019 */
9971020Phaser . TilemapLayer . prototype . _unfixX = function ( x ) {
9981021
999- if ( this . scrollFactorX === 1 )
1022+ if ( this . scrollFactorX === 1 && ! this . _camDetatched )
10001023 {
10011024 return x ;
10021025 }
@@ -1020,7 +1043,7 @@ Phaser.TilemapLayer.prototype._fixY = function (y) {
10201043 y = 0 ;
10211044 }
10221045
1023- if ( this . scrollFactorY === 1 )
1046+ if ( this . scrollFactorY === 1 && ! this . _camDetatched )
10241047 {
10251048 return y ;
10261049 }
@@ -1039,7 +1062,7 @@ Phaser.TilemapLayer.prototype._fixY = function (y) {
10391062 */
10401063Phaser . TilemapLayer . prototype . _unfixY = function ( y ) {
10411064
1042- if ( this . scrollFactorY === 1 )
1065+ if ( this . scrollFactorY === 1 && ! this . _camDetatched )
10431066 {
10441067 return y ;
10451068 }
@@ -1236,6 +1259,54 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "y", {
12361259
12371260} ) ;
12381261
1262+ /**
1263+ * The x position of this Tilemap Layer.
1264+ *
1265+ * @property {integer } x
1266+ * @memberof Phaser.TilemapLayer
1267+ * @public
1268+ */
1269+ Object . defineProperty ( Phaser . TilemapLayer . prototype , "offsetX" , {
1270+
1271+ get : function ( ) {
1272+
1273+ if ( this . _camDetatched )
1274+ {
1275+ return this . cameraOffset . x - this . view . x ;
1276+ }
1277+ else
1278+ {
1279+ return this . cameraOffset . x ;
1280+ }
1281+
1282+ }
1283+
1284+ } ) ;
1285+
1286+ /**
1287+ * The y position of this Tilemap Layer.
1288+ *
1289+ * @property {integer } y
1290+ * @memberof Phaser.TilemapLayer
1291+ * @public
1292+ */
1293+ Object . defineProperty ( Phaser . TilemapLayer . prototype , "offsetY" , {
1294+
1295+ get : function ( ) {
1296+
1297+ if ( this . _camDetatched )
1298+ {
1299+ return this . cameraOffset . y - this . view . y ;
1300+ }
1301+ else
1302+ {
1303+ return this . cameraOffset . y ;
1304+ }
1305+
1306+ }
1307+
1308+ } ) ;
1309+
12391310Object . defineProperty ( Phaser . TilemapLayer . prototype , "bottom" , {
12401311
12411312 get : function ( ) {
@@ -1291,11 +1362,15 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "wrap", {
12911362Object . defineProperty ( Phaser . TilemapLayer . prototype , "scrollX" , {
12921363
12931364 get : function ( ) {
1365+
12941366 return this . _scrollX ;
1367+
12951368 } ,
12961369
12971370 set : function ( value ) {
1371+
12981372 this . _scrollX = value ;
1373+
12991374 }
13001375
13011376} ) ;
@@ -1310,11 +1385,15 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
13101385Object . defineProperty ( Phaser . TilemapLayer . prototype , "scrollY" , {
13111386
13121387 get : function ( ) {
1388+
13131389 return this . _scrollY ;
1390+
13141391 } ,
13151392
13161393 set : function ( value ) {
1394+
13171395 this . _scrollY = value ;
1396+
13181397 }
13191398
13201399} ) ;
@@ -1329,12 +1408,16 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
13291408Object . defineProperty ( Phaser . TilemapLayer . prototype , "collisionWidth" , {
13301409
13311410 get : function ( ) {
1411+
13321412 return this . _mc . cw ;
1413+
13331414 } ,
13341415
13351416 set : function ( value ) {
1417+
13361418 this . _mc . cw = value | 0 ;
13371419 this . dirty = true ;
1420+
13381421 }
13391422
13401423} ) ;
@@ -1349,12 +1432,16 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", {
13491432Object . defineProperty ( Phaser . TilemapLayer . prototype , "collisionHeight" , {
13501433
13511434 get : function ( ) {
1435+
13521436 return this . _mc . ch ;
1437+
13531438 } ,
13541439
13551440 set : function ( value ) {
1441+
13561442 this . _mc . ch = value | 0 ;
13571443 this . dirty = true ;
1444+
13581445 }
13591446
13601447} ) ;
0 commit comments