@@ -22,6 +22,7 @@ var SnapCeil = require('../../math/snap/SnapCeil');
2222 */
2323var CullTiles = function ( layer , camera , outputArray , renderOrder )
2424{
25+
2526 if ( outputArray === undefined ) { outputArray = [ ] ; }
2627 if ( renderOrder === undefined ) { renderOrder = 0 ; }
2728
@@ -44,104 +45,201 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
4445 var drawRight = mapWidth ;
4546 var drawTop = 0 ;
4647 var drawBottom = mapHeight ;
47-
48- if ( ! tilemapLayer . skipCull && tilemapLayer . scrollFactorX === 1 && tilemapLayer . scrollFactorY === 1 )
49- {
50- // Camera world view bounds, snapped for scaled tile size
51- // Cull Padding values are given in tiles, not pixels
52-
53- var boundsLeft = SnapFloor ( camera . worldView . x - tilemapLayer . x , tileW , 0 , true ) - tilemapLayer . cullPaddingX ;
54- var boundsRight = SnapCeil ( camera . worldView . right - tilemapLayer . x , tileW , 0 , true ) + tilemapLayer . cullPaddingX ;
55- var boundsTop = SnapFloor ( camera . worldView . y - tilemapLayer . y , tileH , 0 , true ) - tilemapLayer . cullPaddingY ;
56- var boundsBottom = SnapCeil ( camera . worldView . bottom - tilemapLayer . y , tileH , 0 , true ) + tilemapLayer . cullPaddingY ;
57-
58- drawLeft = Math . max ( 0 , boundsLeft ) ;
59- drawRight = Math . min ( mapWidth , boundsRight ) ;
60- drawTop = Math . max ( 0 , boundsTop ) ;
61- drawBottom = Math . min ( mapHeight , boundsBottom ) ;
62- }
63-
48+ var inIsoBounds = function ( x , y ) { return true ; }
49+ if ( ! tilemapLayer . skipCull && tilemapLayer . scrollFactorX === 1 && tilemapLayer . scrollFactorY === 1 ) {
50+ if ( layer . orientation == "orthogonal" ) {
51+ // Camera world view bounds, snapped for scaled tile size
52+ // Cull Padding values are given in tiles, not pixels
53+
54+ var boundsLeft = SnapFloor ( camera . worldView . x - tilemapLayer . x , tileW , 0 , true ) - tilemapLayer . cullPaddingX ;
55+ var boundsRight = SnapCeil ( camera . worldView . right - tilemapLayer . x , tileW , 0 , true ) + tilemapLayer . cullPaddingX ;
56+ var boundsTop = SnapFloor ( camera . worldView . y - tilemapLayer . y , tileH , 0 , true ) - tilemapLayer . cullPaddingY ;
57+ var boundsBottom = SnapCeil ( camera . worldView . bottom - tilemapLayer . y , tileH , 0 , true ) + tilemapLayer . cullPaddingY ;
58+
59+ drawLeft = Math . max ( 0 , boundsLeft ) ;
60+ drawRight = Math . min ( mapWidth , boundsRight ) ;
61+ drawTop = Math . max ( 0 , boundsTop ) ;
62+ drawBottom = Math . min ( mapHeight , boundsBottom ) ;
63+ } else if ( layer . orientation == "isometric" ) {
64+ inIsoBounds = function ( x , y ) {
65+ var pos = tilemapLayer . tileToWorldXY ( x , y , undefined , camera )
66+ return ( pos . x > camera . worldView . x && pos . x < camera . worldView . right ) && ( pos . y > camera . worldView . y && pos . y < camera . worldView . bottom )
67+ }
68+ }
69+ }
6470 var x ;
6571 var y ;
6672 var tile ;
6773
68- if ( renderOrder === 0 )
69- {
70- // right-down
7174
72- for ( y = drawTop ; y < drawBottom ; y ++ )
75+ if ( layer . orientation == "orthogonal" ) {
76+
77+ if ( renderOrder === 0 )
7378 {
74- for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
75- {
76- tile = mapData [ y ] [ x ] ;
79+ // right-down
7780
78- if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
81+ for ( y = drawTop ; y < drawBottom ; y ++ )
82+ {
83+ for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
7984 {
80- continue ;
81- }
85+ tile = mapData [ y ] [ x ] ;
8286
83- outputArray . push ( tile ) ;
87+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
88+ {
89+ continue ;
90+ }
91+
92+ outputArray . push ( tile ) ;
93+ }
8494 }
8595 }
86- }
87- else if ( renderOrder === 1 )
88- {
89- // left-down
90-
91- for ( y = drawTop ; y < drawBottom ; y ++ )
96+ else if ( renderOrder === 1 )
9297 {
93- for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
94- {
95- tile = mapData [ y ] [ x ] ;
98+ // left-down
9699
97- if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
100+ for ( y = drawTop ; y < drawBottom ; y ++ )
101+ {
102+ for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
98103 {
99- continue ;
100- }
104+ tile = mapData [ y ] [ x ] ;
101105
102- outputArray . push ( tile ) ;
106+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
107+ {
108+ continue ;
109+ }
110+
111+ outputArray . push ( tile ) ;
112+ }
103113 }
104114 }
105- }
106- else if ( renderOrder === 2 )
107- {
108- // right-up
109-
110- for ( y = drawBottom ; y >= drawTop ; y -- )
115+ else if ( renderOrder === 2 )
111116 {
112- for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
113- {
114- tile = mapData [ y ] [ x ] ;
117+ // right-up
115118
116- if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
119+ for ( y = drawBottom ; y >= drawTop ; y -- )
120+ {
121+ for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
117122 {
118- continue ;
123+ tile = mapData [ y ] [ x ] ;
124+
125+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
126+ {
127+ continue ;
128+ }
129+
130+ outputArray . push ( tile ) ;
119131 }
132+ }
133+ }
134+ else if ( renderOrder === 3 )
135+ {
136+ // left-up
137+
138+ for ( y = drawBottom ; y >= drawTop ; y -- )
139+ {
140+ for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
141+ {
142+ tile = mapData [ y ] [ x ] ;
120143
121- outputArray . push ( tile ) ;
144+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
145+ {
146+ continue ;
147+ }
148+
149+ outputArray . push ( tile ) ;
150+ }
122151 }
123152 }
124- }
125- else if ( renderOrder === 3 )
126- {
127- // left-up
153+ } else if ( layer . orientation == "isometric" ) {
154+ if ( renderOrder === 0 )
155+ {
156+ // right-down
128157
129- for ( y = drawBottom ; y >= drawTop ; y -- )
158+ for ( y = drawTop ; y < drawBottom ; y ++ )
159+ {
160+ for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
161+ {
162+ if ( inIsoBounds ( x , y ) ) {
163+ tile = mapData [ y ] [ x ] ;
164+
165+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
166+ {
167+ continue ;
168+ }
169+
170+ outputArray . push ( tile ) ;
171+ }
172+
173+ }
174+ }
175+ }
176+ else if ( renderOrder === 1 )
130177 {
131- for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
178+ // left-down
179+
180+ for ( y = drawTop ; y < drawBottom ; y ++ )
132181 {
133- tile = mapData [ y ] [ x ] ;
182+ for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
183+ {
184+ if ( inIsoBounds ( x , y ) ) {
185+ tile = mapData [ y ] [ x ] ;
186+
187+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
188+ {
189+ continue ;
190+ }
191+
192+ outputArray . push ( tile ) ;
193+ }
194+ }
195+ }
196+ }
197+ else if ( renderOrder === 2 )
198+ {
199+ // right-up
134200
135- if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
201+ for ( y = drawBottom ; y >= drawTop ; y -- )
202+ {
203+ for ( x = drawLeft ; mapData [ y ] && x < drawRight ; x ++ )
136204 {
137- continue ;
205+ if ( inIsoBounds ( x , y ) ) {
206+ tile = mapData [ y ] [ x ] ;
207+
208+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
209+ {
210+ continue ;
211+ }
212+
213+ outputArray . push ( tile ) ;
214+ }
138215 }
216+ }
217+ }
218+ else if ( renderOrder === 3 )
219+ {
220+ // left-up
139221
140- outputArray . push ( tile ) ;
222+ for ( y = drawBottom ; y >= drawTop ; y -- )
223+ {
224+ for ( x = drawRight ; mapData [ y ] && x >= drawLeft ; x -- )
225+ {
226+ if ( inIsoBounds ( x , y ) ) {
227+ tile = mapData [ y ] [ x ] ;
228+
229+ if ( ! tile || tile . index === - 1 || ! tile . visible || tile . alpha === 0 )
230+ {
231+ continue ;
232+ }
233+
234+ outputArray . push ( tile ) ;
235+ }
236+ }
141237 }
142238 }
239+
143240 }
144241
242+
145243 tilemapLayer . tilesDrawn = outputArray . length ;
146244 tilemapLayer . tilesTotal = mapWidth * mapHeight ;
147245
0 commit comments