@@ -151,6 +151,12 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
151151 */
152152 this . dirty = true ;
153153
154+ /**
155+ * @property {number } rayStepRate - When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
156+ * @default
157+ */
158+ this . rayStepRate = 4 ;
159+
154160 /**
155161 * @property {number } _cw - Local collision var.
156162 * @private
@@ -457,17 +463,46 @@ Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
457463/**
458464* Gets all tiles that intersect with the given line.
459465*
460- * @method Phaser.TilemapLayer#getIntersectingTiles
466+ * @method Phaser.TilemapLayer#getRayCastTiles
461467* @memberof Phaser.TilemapLayer
462468* @param {Phaser.Line } line - The line used to determine which tiles to return.
469+ * @param {number } [stepRate] - How many steps through the ray will we check? If undefined or null it uses TilemapLayer.rayStepRate.
470+ * @param {boolean } [collides=false] - If true only return tiles that collide on one or more faces.
471+ * @param {boolean } [interestingFace=false] - If true only return tiles that have interesting faces.
463472* @return {array<Phaser.Tile> } An array of Phaser.Tiles.
464473*/
465- Phaser . TilemapLayer . prototype . getIntersectingTiles = function ( line ) {
474+ Phaser . TilemapLayer . prototype . getRayCastTiles = function ( line , stepRate , collides , interestingFace ) {
466475
467- var tiles = this . getTiles ( x , y , width , height , false ) ;
476+ if ( typeof stepRate === 'undefined' || stepRate === null ) { stepRate = this . rayStepRate ; }
477+ if ( typeof collides === 'undefined' ) { collides = false ; }
478+ if ( typeof interestingFace === 'undefined' ) { interestingFace = false ; }
479+
480+ // First get all tiles that touch the bounds of the line
481+ var tiles = this . getTiles ( line . x , line . y , line . width , line . height , collides , interestingFace ) ;
468482
483+ if ( tiles . length === 0 )
484+ {
485+ return [ ] ;
486+ }
469487
470- return tiles ;
488+ // Now we only want the tiles that intersect with the points on this line
489+ var coords = line . coordinatesOnLine ( stepRate ) ;
490+ var total = coords . length ;
491+ var results = [ ] ;
492+
493+ for ( var i = 0 ; i < tiles . length ; i ++ )
494+ {
495+ for ( var t = 0 ; t < total ; t ++ )
496+ {
497+ if ( tiles [ i ] . containsPoint ( coords [ t ] [ 0 ] , coords [ t ] [ 1 ] ) )
498+ {
499+ results . push ( tiles [ i ] ) ;
500+ break ;
501+ }
502+ }
503+ }
504+
505+ return results ;
471506
472507}
473508
@@ -589,8 +624,6 @@ Phaser.TilemapLayer.prototype.render = function () {
589624
590625 var tile ;
591626 var set ;
592- // var ox = 0;
593- // var oy = 0;
594627
595628 if ( this . debug )
596629 {
@@ -618,11 +651,11 @@ Phaser.TilemapLayer.prototype.render = function () {
618651
619652 set . draw ( this . context , Math . floor ( this . _tx ) , Math . floor ( this . _ty ) , tile . index ) ;
620653
621- // if (tile.debug)
622- // {
623- // this.context.fillStyle = 'rgba(0, 255, 0, 0.4)';
624- // this.context.fillRect(Math.floor(this._tx), Math.floor(this._ty), this.map.tileWidth, this.map.tileHeight);
625- // }
654+ if ( tile . debug )
655+ {
656+ this . context . fillStyle = 'rgba(0, 255, 0, 0.4)' ;
657+ this . context . fillRect ( Math . floor ( this . _tx ) , Math . floor ( this . _ty ) , this . map . tileWidth , this . map . tileHeight ) ;
658+ }
626659 }
627660
628661 this . _tx += this . map . tileWidth ;
0 commit comments