@@ -123,15 +123,105 @@ var StaticTilemapLayer = new Class({
123123 this . tileset = tileset ;
124124
125125 /**
126- * Used internally with the canvas render. This holds the tiles that are visible within the
127- * camera.
126+ * Used internally by the Canvas renderer.
127+ * This holds the tiles that are visible within the camera in the last frame .
128128 *
129129 * @name Phaser.Tilemaps.StaticTilemapLayer#culledTiles
130130 * @type {array }
131131 * @since 3.0.0
132132 */
133133 this . culledTiles = [ ] ;
134134
135+ /**
136+ * Canvas only.
137+ *
138+ * You can control if the Cameras should cull tiles before rendering them or not.
139+ * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer.
140+ *
141+ * However, there are some instances when you may wish to disable this, and toggling this flag allows
142+ * you to do so. Also see `setSkipCull` for a chainable method that does the same thing.
143+ *
144+ * @name Phaser.Tilemaps.StaticTilemapLayer#skipCull
145+ * @type {boolean }
146+ * @since 3.12.0
147+ */
148+ this . skipCull = false ;
149+
150+ /**
151+ * Canvas only.
152+ *
153+ * The total number of tiles drawn by the renderer in the last frame.
154+ *
155+ * This only works when rending with Canvas.
156+ *
157+ * @name Phaser.Tilemaps.StaticTilemapLayer#tilesDrawn
158+ * @type {integer }
159+ * @readOnly
160+ * @since 3.12.0
161+ */
162+ this . tilesDrawn = 0 ;
163+
164+ /**
165+ * Canvas only.
166+ *
167+ * The total number of tiles in this layer. Updated every frame.
168+ *
169+ * @name Phaser.Tilemaps.StaticTilemapLayer#tilesTotal
170+ * @type {integer }
171+ * @readOnly
172+ * @since 3.12.0
173+ */
174+ this . tilesTotal = this . layer . width * this . layer . height ;
175+
176+ /**
177+ * Canvas only.
178+ *
179+ * The amount of extra tiles to add into the cull rectangle when calculating its horizontal size.
180+ *
181+ * See the method `setCullPadding` for more details.
182+ *
183+ * @name Phaser.Tilemaps.StaticTilemapLayer#cullPaddingX
184+ * @type {integer }
185+ * @default 1
186+ * @since 3.12.0
187+ */
188+ this . cullPaddingX = 1 ;
189+
190+ /**
191+ * Canvas only.
192+ *
193+ * The amount of extra tiles to add into the cull rectangle when calculating its vertical size.
194+ *
195+ * See the method `setCullPadding` for more details.
196+ *
197+ * @name Phaser.Tilemaps.StaticTilemapLayer#cullPaddingY
198+ * @type {integer }
199+ * @default 1
200+ * @since 3.12.0
201+ */
202+ this . cullPaddingY = 1 ;
203+
204+ /**
205+ * Canvas only.
206+ *
207+ * The callback that is invoked when the tiles are culled.
208+ *
209+ * By default it will call `TilemapComponents.CullTiles` but you can override this to call any function you like.
210+ *
211+ * It will be sent 3 arguments:
212+ *
213+ * 1) The Phaser.Tilemaps.LayerData object for this Layer
214+ * 2) The Camera that is culling the layer. You can check its `dirty` property to see if it has changed since the last cull.
215+ * 3) A reference to the `culledTiles` array, which should be used to store the tiles you want rendered.
216+ *
217+ * See the `TilemapComponents.CullTiles` source code for details on implementing your own culling system.
218+ *
219+ * @name Phaser.Tilemaps.StaticTilemapLayer#cullCallback
220+ * @type {function }
221+ * @since 3.12.0
222+ */
223+ this . cullCallback = TilemapComponents . CullTiles ;
224+
135225 /**
136226 * @name Phaser.Tilemaps.StaticTilemapLayer#vertexBuffer
137227 * @type {array }
@@ -458,28 +548,59 @@ var StaticTilemapLayer = new Class({
458548 */
459549 cull : function ( camera )
460550 {
461- return TilemapComponents . CullTiles ( this . layer , camera , this . culledTiles ) ;
551+ return this . cullCallback ( this . layer , camera , this . culledTiles ) ;
462552 } ,
463553
464554 /**
465- * Destroys this StaticTilemapLayer and removes its link to the associated LayerData.
555+ * Canvas only.
556+ *
557+ * You can control if the Cameras should cull tiles before rendering them or not.
558+ * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer.
466559 *
467- * @method Phaser.Tilemaps.StaticTilemapLayer#destroy
468- * @since 3.0.0
560+ * However, there are some instances when you may wish to disable this.
561+ *
562+ * @method Phaser.Tilemaps.StaticTilemapLayer#setSkipCull
563+ * @since 3.12.0
564+ *
565+ * @param {boolean } [value=true] - Set to `true` to stop culling tiles. Set to `false` to enable culling again.
566+ *
567+ * @return {this } This Tilemap Layer object.
469568 */
470- destroy : function ( )
569+ setSkipCull : function ( value )
471570 {
472- // Uninstall this layer only if it is still installed on the LayerData object
473- if ( this . layer . tilemapLayer === this )
474- {
475- this . layer . tilemapLayer = undefined ;
476- }
571+ if ( value === undefined ) { value = true ; }
477572
478- this . tilemap = undefined ;
479- this . layer = undefined ;
480- this . tileset = undefined ;
573+ this . skipCull = value ;
481574
482- GameObject . prototype . destroy . call ( this ) ;
575+ return this ;
576+ } ,
577+
578+ /**
579+ * Canvas only.
580+ *
581+ * When a Camera culls the tiles in this layer it does so using its view into the world, building up a
582+ * rectangle inside which the tiles must exist or they will be culled. Sometimes you may need to expand the size
583+ * of this 'cull rectangle', especially if you plan on rotating the Camera viewing the layer. Do so
584+ * by providing the padding values. The values given are in tiles, not pixels. So if the tile width was 32px
585+ * and you set `paddingX` to be 4, it would add 32px x 4 to the cull rectangle (adjusted for scale)
586+ *
587+ * @method Phaser.Tilemaps.StaticTilemapLayer#setCullPadding
588+ * @since 3.12.0
589+ *
590+ * @param {integer } [paddingX=1] - The amount of extra horizontal tiles to add to the cull check padding.
591+ * @param {integer } [paddingY=1] - The amount of extra vertical tiles to add to the cull check padding.
592+ *
593+ * @return {this } This Tilemap Layer object.
594+ */
595+ setCullPadding : function ( paddingX , paddingY )
596+ {
597+ if ( paddingX === undefined ) { paddingX = 1 ; }
598+ if ( paddingY === undefined ) { paddingY = 1 ; }
599+
600+ this . cullPaddingX = paddingX ;
601+ this . cullPaddingY = paddingY ;
602+
603+ return this ;
483604 } ,
484605
485606 /**
@@ -1052,7 +1173,30 @@ var StaticTilemapLayer = new Class({
10521173 worldToTileXY : function ( worldX , worldY , snapToFloor , point , camera )
10531174 {
10541175 return TilemapComponents . WorldToTileXY ( worldX , worldY , snapToFloor , point , camera , this . layer ) ;
1055- }
1176+ } ,
1177+
1178+ /**
1179+ * Destroys this StaticTilemapLayer and removes its link to the associated LayerData.
1180+ *
1181+ * @method Phaser.Tilemaps.StaticTilemapLayer#destroy
1182+ * @since 3.0.0
1183+ */
1184+ destroy : function ( )
1185+ {
1186+ // Uninstall this layer only if it is still installed on the LayerData object
1187+ if ( this . layer . tilemapLayer === this )
1188+ {
1189+ this . layer . tilemapLayer = undefined ;
1190+ }
1191+
1192+ this . tilemap = undefined ;
1193+ this . layer = undefined ;
1194+ this . tileset = undefined ;
1195+ this . culledTiles . length = 0 ;
1196+ this . cullCallback = null ;
1197+
1198+ GameObject . prototype . destroy . call ( this ) ;
1199+ } ,
10561200
10571201} ) ;
10581202
0 commit comments