@@ -137,6 +137,7 @@ Phaser.Tileset.prototype = {
137137
138138 if ( coordIndex >= 0 && ( coordIndex + 1 ) < this . drawCoords . length )
139139 {
140+ // draw the tile on the canvas
140141 context . drawImage (
141142 this . image ,
142143 this . drawCoords [ coordIndex ] ,
@@ -152,6 +153,45 @@ Phaser.Tileset.prototype = {
152153
153154 } ,
154155
156+ /**
157+ * Draws a tile from this Tileset at the given coordinates.
158+ *
159+ * @method Phaser.Tileset#draw
160+ * @public
161+ * @param {Array } glBatch - A list of webgl batch objects to draw later.
162+ * @param {number } x - The x coordinate to draw to.
163+ * @param {number } y - The y coordinate to draw to.
164+ * @param {integer } index - The index of the tile within the set to draw.
165+ */
166+ drawGl : function ( glBatch , x , y , index ) {
167+
168+ // Correct the tile index for the set and bias for interlacing x/y values
169+ var coordIndex = ( index - this . firstgid ) * 2 ;
170+
171+ if ( coordIndex >= 0 && ( coordIndex + 1 ) < this . drawCoords . length )
172+ {
173+ // add the tile to the webgl batch
174+ if ( ! glBatch )
175+ {
176+ glBatch = [ ] ;
177+ }
178+
179+ // source and destination coordinates, in pixel units
180+ // destination is the centre of the tile
181+ glBatch . push ( {
182+ sx : this . drawCoords [ coordIndex ] ,
183+ sy : this . drawCoords [ coordIndex + 1 ] ,
184+ sw : this . tileWidth ,
185+ sh : this . tileHeight ,
186+ dx : x + this . tileWidth * 0.5 ,
187+ dy : y + this . tileHeight * 0.5 ,
188+ dw : this . tileWidth ,
189+ dh : this . tileHeight
190+ } ) ;
191+ }
192+
193+ } ,
194+
155195 /**
156196 * Returns true if and only if this tileset contains the given tile index.
157197 *
0 commit comments