@@ -54,15 +54,21 @@ public void draw(GameCanvas canvas){
54
54
int i = 0 ;
55
55
for (float y = levelHeight - 1 ; y >= 0 ; y --){
56
56
for (float x = 0 ; x < levelWidth ; x ++){
57
- if (levelTiles [i ] > 0 ) {
58
- TextureRegion tileTexture = tileset [levelTiles [i ] - fid ];
59
- if (tileSize == 512 ) {
60
- canvas .draw (tileTexture , Color .WHITE , 0 , 0 , (x +offset .x ) * 128 * textureScale .x ,
61
- (y +offset .y ) * 128 * textureScale .y , 0 , textureScale .x , textureScale .y );
62
- } else {
63
- canvas .draw (tileTexture , Color .WHITE , 0 , 0 , (x +offset .x ) * tileSize * textureScale .x ,
64
- (y +offset .y ) * tileSize * textureScale .y , 0 , textureScale .x , textureScale .y );
57
+ try {
58
+ if (levelTiles [i ] > 0 ) {
59
+ TextureRegion tileTexture = tileset [levelTiles [i ] - fid ];
60
+ if (tileSize == 512 ) {
61
+ canvas .draw (tileTexture , Color .WHITE , 0 , 0 , (x + offset .x ) * 128 * textureScale .x ,
62
+ (y + offset .y ) * 128 * textureScale .y , 0 , textureScale .x , textureScale .y );
63
+ } else {
64
+ canvas .draw (tileTexture , Color .WHITE , 0 , 0 , (x + offset .x ) * tileSize * textureScale .x ,
65
+ (y + offset .y ) * tileSize * textureScale .y , 0 , textureScale .x , textureScale .y );
66
+ }
65
67
}
68
+ } catch (ArrayIndexOutOfBoundsException e ) {
69
+ System .err .println ("WARNING: tile " + i + " at (" + x +", " + y + ") has invalid id " +
70
+ levelTiles [i ] + ". (fid is " + fid + ", tileset size is " + tileset .length + ")." );
71
+ levelTiles [i ] = 0 ;
66
72
}
67
73
i ++;
68
74
}
0 commit comments