@@ -105,28 +105,27 @@ class FlxTiledSprite extends FlxStrip
105105 graphic = FlxGraphic .fromFrame (frame );
106106 return this ;
107107 }
108-
109- override function set_clipRect (Value : FlxRect ): FlxRect
108+
109+ override function set_clipRect (value : FlxRect ): FlxRect
110110 {
111- if (Value != clipRect )
112- regen = true ;
113-
114- return super .set_clipRect (Value );
111+ regen = true ;
112+
113+ return super .set_clipRect (value );
115114 }
116-
117- override function set_graphic (Value : FlxGraphic ): FlxGraphic
115+
116+ override function set_graphic (value : FlxGraphic ): FlxGraphic
118117 {
119118 if (graphic != value )
120119 regen = true ;
121-
120+
122121 return super .set_graphic (value );
123122 }
124123
125124 function regenGraphic (): Void
126125 {
127126 if (! regen || graphic == null )
128127 return ;
129-
128+
130129 if (FlxG .renderBlit )
131130 {
132131 updateRenderSprite ();
@@ -143,7 +142,7 @@ class FlxTiledSprite extends FlxStrip
143142 {
144143 if (regen )
145144 regenGraphic ();
146-
145+
147146 if (graphicVisible )
148147 {
149148 if (FlxG .renderBlit )
@@ -174,7 +173,7 @@ class FlxTiledSprite extends FlxStrip
174173 {
175174 if (ignoreDrawDebug )
176175 return ;
177-
176+
178177 final drawPath = path != null && ! path .ignoreDrawDebug ;
179178
180179 for (camera in getCamerasLegacy ())
@@ -195,13 +194,13 @@ class FlxTiledSprite extends FlxStrip
195194
196195 if (renderSprite == null )
197196 renderSprite = new FlxSprite ();
198-
197+
199198 final drawRect = getDrawRect ();
200199 drawRect .x = Std .int (drawRect .x );
201200 drawRect .y = Std .int (drawRect .y );
202201 drawRect .width = Std .int (drawRect .width );
203202 drawRect .height = Std .int (drawRect .height );
204- // TODO: rect.int() or smth
203+ // TODO: rect.int() or smth
205204
206205 if (drawRect .width * drawRect .height == 0 )
207206 {
@@ -243,104 +242,139 @@ class FlxTiledSprite extends FlxStrip
243242 {
244243 if (graphic == null )
245244 return ;
246-
245+
247246 final frame : FlxFrame = graphic .imageFrame .frame ;
248247 graphicVisible = true ;
249-
250- var rectX : Float = (repeatX ? 0 : scrollX );
251- rectX = FlxMath .bound (rectX , 0 , width );
252- if (clipRect != null ) rectX + = clipRect .x ;
253-
254- var rectWidth : Float = (repeatX ? rectX + width : scrollX + frame .sourceSize .x );
255- if (clipRect != null ) rectWidth = FlxMath .bound (rectWidth , clipRect .x , clipRect .x + clipRect .width );
256-
248+
249+ final drawRect = getDrawRect ();
250+
251+ if (drawRect .width * drawRect .height == 0 )
252+ {
253+ graphicVisible = false ;
254+ drawRect .put ();
255+ return ;
256+ }
257+
257258 // Texture coordinates (UVs)
258- var rectUX : Float = (rectX - scrollX ) / frame .sourceSize .x ;
259- var rectVX : Float = rectUX + (rectWidth - rectX ) / frame .sourceSize .x ;
260-
261- vertices [0 ] = rectX ;
262- vertices [2 ] = rectWidth ;
263- vertices [4 ] = rectWidth ;
264- vertices [6 ] = rectX ;
265-
259+ final rectUX : Float = (drawRect .x - scrollX ) / frame .sourceSize .x ;
260+ final rectVX : Float = rectUX + (drawRect .width - drawRect .x ) / frame .sourceSize .x ;
261+ final rectUY : Float = (drawRect .y - scrollY ) / frame .sourceSize .y ;
262+ final rectVY : Float = rectUY + (drawRect .height - drawRect .y ) / frame .sourceSize .y ;
263+
264+ vertices [0 ] = drawRect .x ;
265+ vertices [2 ] = drawRect .width ;
266+ vertices [4 ] = drawRect .width ;
267+ vertices [6 ] = drawRect .x ;
268+
266269 uvtData [0 ] = rectUX ;
267270 uvtData [2 ] = rectVX ;
268271 uvtData [4 ] = rectVX ;
269272 uvtData [6 ] = rectUX ;
270-
271- var rectY : Float = (repeatY ? 0 : scrollY );
272- rectY = FlxMath .bound (rectY , 0 , height );
273- if (clipRect != null ) rectY + = clipRect .y ;
274-
275- var rectHeight : Float = (repeatY ? rectY + height : scrollY + frame .sourceSize .y );
276- if (clipRect != null ) rectHeight = FlxMath .bound (rectHeight , clipRect .y , clipRect .y + clipRect .height );
277-
278- // Texture coordinates (UVs)
279- var rectUY : Float = (rectY - scrollY ) / frame .sourceSize .y ;
280- var rectVY : Float = rectUY + (rectHeight - rectY ) / frame .sourceSize .y ;
281-
282- vertices [1 ] = rectY ;
283- vertices [3 ] = rectY ;
284- vertices [5 ] = rectHeight ;
285- vertices [7 ] = rectHeight ;
286-
273+
274+ vertices [1 ] = drawRect .y ;
275+ vertices [3 ] = drawRect .y ;
276+ vertices [5 ] = drawRect .height ;
277+ vertices [7 ] = drawRect .height ;
278+
287279 uvtData [1 ] = rectUY ;
288280 uvtData [3 ] = rectUY ;
289281 uvtData [5 ] = rectVY ;
290282 uvtData [7 ] = rectVY ;
283+
284+ drawRect .put ();
291285 }
292-
293- override function set_width (Width : Float ): Float
286+
287+ function getDrawRect (? result : FlxRect ): FlxRect
288+ {
289+ if (result == null )
290+ result = FlxRect .get ();
291+
292+ final frame : FlxFrame = graphic .imageFrame .frame ;
293+ final sourceSizeX = FlxG .renderBlit ? graphic .bitmap .width : frame .sourceSize .x ;
294+ final sourceSizeY = FlxG .renderBlit ? graphic .bitmap .height : frame .sourceSize .y ;
295+
296+ result .x = (repeatX ? 0 : scrollX );
297+ if (clipRect != null )
298+ {
299+ result .x + = clipRect .x ;
300+ }
301+ result .x = FlxMath .bound (result .x , 0 , width );
302+
303+ result .width = (repeatX ? result .x + width : scrollX + sourceSizeX );
304+ if (clipRect != null )
305+ {
306+ result .width = FlxMath .bound (result .width , clipRect .x , clipRect .right );
307+ }
308+ result .width = FlxMath .bound (result .width , 0 , width );
309+
310+ result .y = (repeatY ? 0 : scrollY );
311+ if (clipRect != null )
312+ {
313+ result .y + = clipRect .y ;
314+ }
315+ result .y = FlxMath .bound (result .y , 0 , height );
316+
317+ result .height = (repeatY ? result .y + height : scrollY + sourceSizeY );
318+ if (clipRect != null )
319+ {
320+ result .height = FlxMath .bound (result .height , clipRect .y , clipRect .bottom );
321+ }
322+ result .height = FlxMath .bound (result .height , 0 , height );
323+
324+ return result ;
325+ }
326+
327+ override function set_width (value : Float ): Float
294328 {
295329 if (value <= 0 )
296330 return value ;
297-
331+
298332 if (value != width )
299333 regen = true ;
300-
334+
301335 return super .set_width (value );
302336 }
303337
304338 override function set_height (value : Float ): Float
305339 {
306340 if (value <= 0 )
307341 return value ;
308-
342+
309343 if (value != height )
310344 regen = true ;
311-
345+
312346 return super .set_height (value );
313347 }
314348
315349 function set_scrollX (value : Float ): Float
316350 {
317351 if (value != scrollX )
318352 regen = true ;
319-
353+
320354 return scrollX = value ;
321355 }
322356
323357 function set_scrollY (value : Float ): Float
324358 {
325359 if (value != scrollY )
326360 regen = true ;
327-
361+
328362 return scrollY = value ;
329363 }
330364
331365 function set_repeatX (value : Bool ): Bool
332366 {
333367 if (value != repeatX )
334368 regen = true ;
335-
369+
336370 return repeatX = value ;
337371 }
338372
339373 function set_repeatY (value : Bool ): Bool
340374 {
341375 if (value != repeatY )
342376 regen = true ;
343-
377+
344378 return repeatY = value ;
345379 }
346380}
0 commit comments