@@ -151,13 +151,6 @@ Phaser.Tilemap = function (game, key, tileWidth, tileHeight, width, height) {
151151 */
152152 this . debugMap = [ ] ;
153153
154- /**
155- * 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- * @property {integer } rayStepRate
157- * @default
158- */
159- this . rayStepRate = 4 ;
160-
161154 /**
162155 * @property {array } _results - Internal var.
163156 * @private
@@ -1988,256 +1981,6 @@ Phaser.Tilemap.prototype = {
19881981
19891982 } ,
19901983
1991- /**
1992- * Gets all tiles from `Tilemap.layer` that intersect with the given Phaser.Line object.
1993- *
1994- * If you need to get the tiles from a different layer, then set the `layer` property first.
1995- *
1996- * @method Phaser.Tilemap#getRayCastTiles
1997- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
1998- * @param {Phaser.Line } line - The line used to determine which tiles to return.
1999- * @param {integer } [stepRate=(rayStepRate)] - How many steps through the ray will we check? Defaults to `rayStepRate`.
2000- * @param {boolean } [collides=false] - If true, _only_ return tiles that collide on one or more faces.
2001- * @param {boolean } [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
2002- * @return {Phaser.Tile[] } An array of Phaser.Tiles.
2003- */
2004- getRayCastTiles : function ( layer , line , stepRate , collides , interestingFace ) {
2005-
2006- if ( ! stepRate ) { stepRate = this . rayStepRate ; }
2007- if ( collides === undefined ) { collides = false ; }
2008- if ( interestingFace === undefined ) { interestingFace = false ; }
2009-
2010- // First get all tiles that touch the bounds of the line
2011- var tiles = this . getTiles ( layer , line . x , line . y , line . width , line . height , collides , interestingFace ) ;
2012-
2013- if ( tiles . length === 0 )
2014- {
2015- return [ ] ;
2016- }
2017-
2018- // Now we only want the tiles that intersect with the points on this line
2019- var coords = line . coordinatesOnLine ( stepRate ) ;
2020- var results = [ ] ;
2021-
2022- for ( var i = 0 ; i < tiles . length ; i ++ )
2023- {
2024- for ( var t = 0 ; t < coords . length ; t ++ )
2025- {
2026- var tile = tiles [ i ] ;
2027- var coord = coords [ t ] ;
2028-
2029- if ( tile . containsPoint ( coord [ 0 ] , coord [ 1 ] ) )
2030- {
2031- results . push ( tile ) ;
2032- break ;
2033- }
2034- }
2035- }
2036-
2037- return results ;
2038-
2039- } ,
2040-
2041- /**
2042- * Get all Tiles that exist on the current `Tilemap.layer`, within the given area,
2043- * as defined by the top-left corner, width and height arguments.
2044- *
2045- * Values given are in pixels, not tiles.
2046- *
2047- * If you need to get the tiles from a different layer, then set the `layer` property first.
2048- *
2049- * @method Phaser.Tilemap#getTiles
2050- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2051- * @param {number } x - X position of the top left corner (in pixels).
2052- * @param {number } y - Y position of the top left corner (in pixels).
2053- * @param {number } width - Width of the area to get (in pixels).
2054- * @param {number } height - Height of the area to get (in pixels).
2055- * @param {boolean } [collides=false] - If true, _only_ return tiles that collide on one or more faces.
2056- * @param {boolean } [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
2057- * @return {array<Phaser.Tile> } An array of Tiles.
2058- */
2059- getTiles : function ( layer , x , y , width , height , collides , interestingFace ) {
2060-
2061- // Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
2062-
2063- if ( collides === undefined ) { collides = false ; }
2064- if ( interestingFace === undefined ) { interestingFace = false ; }
2065-
2066- var fetchAll = ! ( collides || interestingFace ) ;
2067-
2068- // Adjust the x,y coordinates for scrollFactor
2069- x = this . _fixX ( layer , x ) ;
2070- y = this . _fixY ( layer , y ) ;
2071-
2072- // Convert the pixel values into tile coordinates
2073- var tx = Math . floor ( x / ( layer . _mc . cw * layer . scale . x ) ) ;
2074- var ty = Math . floor ( y / ( layer . _mc . ch * layer . scale . y ) ) ;
2075-
2076- // Don't just use ceil(width/cw) to allow account for x/y diff within cell
2077- var tw = Math . ceil ( ( x + width ) / ( layer . _mc . cw * layer . scale . x ) ) - tx ;
2078- var th = Math . ceil ( ( y + height ) / ( layer . _mc . ch * layer . scale . y ) ) - ty ;
2079-
2080- this . _results . length = 0 ;
2081-
2082- for ( var wy = ty ; wy < ty + th ; wy ++ )
2083- {
2084- for ( var wx = tx ; wx < tx + tw ; wx ++ )
2085- {
2086- var row = layer . layer . data [ wy ] ;
2087-
2088- if ( row && row [ wx ] )
2089- {
2090- if ( fetchAll || row [ wx ] . isInteresting ( collides , interestingFace ) )
2091- {
2092- this . _results . push ( row [ wx ] ) ;
2093- }
2094- }
2095- }
2096- }
2097-
2098- return this . _results . slice ( ) ;
2099-
2100- } ,
2101-
2102- /**
2103- * Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space.
2104- *
2105- * @method Phaser.Tilemap#_fixX
2106- * @private
2107- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2108- * @param {number } x - x coordinate in camera space
2109- * @return {number } x coordinate in scrollFactor-adjusted dimensions
2110- */
2111- _fixX : function ( layer , x ) {
2112-
2113- if ( layer . scrollFactorX === 1 || ( layer . scrollFactorX === 0 && layer . position . x === 0 ) )
2114- {
2115- return x ;
2116- }
2117-
2118- // This executes if the scrollFactorX is 0 and the x position of the tilemap is off from standard.
2119- if ( layer . scrollFactorX === 0 && layer . position . x !== 0 )
2120- {
2121- return x - layer . position . x ;
2122- }
2123-
2124- return layer . _scrollX + ( x - ( layer . _scrollX / layer . scrollFactorX ) ) ;
2125-
2126- } ,
2127-
2128- /**
2129- * Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space.
2130- *
2131- * @method Phaser.Tilemap#_unfixX
2132- * @private
2133- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2134- * @param {number } x - x coordinate in scrollFactor-adjusted dimensions
2135- * @return {number } x coordinate in camera space
2136- */
2137- _unfixX : function ( layer , x ) {
2138-
2139- if ( layer . scrollFactorX === 1 )
2140- {
2141- return x ;
2142- }
2143-
2144- return ( layer . _scrollX / layer . scrollFactorX ) + ( x - layer . _scrollX ) ;
2145-
2146- } ,
2147-
2148- /**
2149- * Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space.
2150- *
2151- * @method Phaser.Tilemap#_fixY
2152- * @private
2153- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2154- * @param {number } y - y coordinate in camera space
2155- * @return {number } y coordinate in scrollFactor-adjusted dimensions
2156- */
2157- _fixY : function ( layer , y ) {
2158-
2159- if ( layer . scrollFactorY === 1 || ( layer . scrollFactorY === 0 && layer . position . y === 0 ) )
2160- {
2161- return y ;
2162- }
2163-
2164- // This executes if the scrollFactorY is 0 and the y position of the tilemap is off from standard.
2165- if ( layer . scrollFactorY === 0 && layer . position . y !== 0 )
2166- {
2167- return y - layer . position . y ;
2168- }
2169-
2170- return layer . _scrollY + ( y - ( layer . _scrollY / layer . scrollFactorY ) ) ;
2171-
2172- } ,
2173-
2174- /**
2175- * Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space.
2176- *
2177- * @method Phaser.Tilemap#_unfixY
2178- * @private
2179- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2180- * @param {number } y - y coordinate in scrollFactor-adjusted dimensions
2181- * @return {number } y coordinate in camera space
2182- */
2183- _unfixY : function ( layer , y ) {
2184-
2185- if ( layer . scrollFactorY === 1 )
2186- {
2187- return y ;
2188- }
2189-
2190- return ( layer . _scrollY / layer . scrollFactorY ) + ( y - layer . _scrollY ) ;
2191-
2192- } ,
2193-
2194- /**
2195- * Convert a pixel value to a tile coordinate.
2196- *
2197- * @method Phaser.Tilemap#getTileX
2198- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2199- * @param {number } x - X position of the point in target tile (in pixels).
2200- * @return {integer } The X map location of the tile.
2201- */
2202- getTileX : function ( layer , x ) {
2203-
2204- return Math . floor ( this . _fixX ( layer , x ) / layer . _mc . tileWidth ) ;
2205-
2206- } ,
2207-
2208- /**
2209- * Convert a pixel value to a tile coordinate.
2210- *
2211- * @method Phaser.Tilemap#getTileY
2212- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2213- * @param {number } y - Y position of the point in target tile (in pixels).
2214- * @return {integer } The Y map location of the tile.
2215- */
2216- getTileY : function ( layer , y ) {
2217-
2218- return Math . floor ( this . _fixY ( layer , y ) / layer . _mc . tileHeight ) ;
2219-
2220- } ,
2221-
2222- /**
2223- * Convert a pixel coordinate to a tile coordinate.
2224- *
2225- * @method Phaser.Tilemap#getTileXY
2226- * @param {Phaser.TilemapLayer|Phaser.TilemapLayerGL } layer - The Tilemap Layer to check.
2227- * @param {number } x - X position of the point in target tile (in pixels).
2228- * @param {number } y - Y position of the point in target tile (in pixels).
2229- * @param {(Phaser.Point|object) } point - The Point/object to update.
2230- * @return {(Phaser.Point|object) } A Point/object with its `x` and `y` properties set.
2231- */
2232- getTileXY : function ( layer , x , y , point ) {
2233-
2234- point . x = this . getTileX ( layer , x ) ;
2235- point . y = this . getTileY ( layer , y ) ;
2236-
2237- return point ;
2238-
2239- } ,
2240-
22411984 /**
22421985 * Removes all layer data from this tile map and nulls the game reference.
22431986 * Note: You are responsible for destroying any TilemapLayer objects you generated yourself, as Tilemap doesn't keep a reference to them.
0 commit comments