Canvas canvas = new Canvas(image);
canvas.scale(scale, scale);
- drawMapLayer(canvas, mapTiles.layers[LayeredTileMap.LAYER_GROUND]);
- tryDrawMapLayer(canvas, LayeredTileMap.LAYER_OBJECTS);
- tryDrawMapLayer(canvas, LayeredTileMap.LAYER_ABOVE);
-
+ synchronized (cachedTiles) {
+ drawMapLayer(canvas, mapTiles.layers[LayeredTileMap.LAYER_GROUND]);
+ tryDrawMapLayer(canvas, LayeredTileMap.LAYER_OBJECTS);
+ tryDrawMapLayer(canvas, LayeredTileMap.LAYER_ABOVE);
+ }
return image;
}
int px = 0;
for (int x = 0; x < map.size.width; ++x, px += tileSize) {
final int tile = layer.tiles[x][y];
- if (tile != 0) {
- canvas.drawBitmap(cachedTiles.bitmaps[tile], px, py, mPaint);
- }
+ if (tile == 0) continue;
+ cachedTiles.drawTile(canvas, tile, px, py, mPaint);
}
}
}
import android.graphics.Paint;
public class TileCollection {
- public final Bitmap[] bitmaps;
+ private final Bitmap[] bitmaps;
+ public final int maxTileID;
public TileCollection(int maxTileID) {
- bitmaps = new Bitmap[maxTileID+1];
+ this.bitmaps = new Bitmap[maxTileID+1];
+ this.maxTileID = maxTileID;
}
public Bitmap getBitmap(int tileID) {
if (w <= 0 || h <= 0) return;
this.scale = world.tileManager.scale;
+ this.mPaint.setFilterBitmap(scale != 1);
this.scaledTileSize = world.tileManager.viewTileSize;
this.surfaceSize = new Size(w, h);
-
- screenSizeTileCount = new Size(
+ this.screenSizeTileCount = new Size(
(int) Math.floor(w / scaledTileSize)
,(int) Math.floor(h / scaledTileSize)
);
Canvas c = null;
try {
c = holder.lockCanvas(redrawRect);
- synchronized (holder) {
+ synchronized (holder) { synchronized (tiles) {
c.translate(screenOffset.x, screenOffset.y);
c.scale(scale, scale);
doDrawRect(c, area);
- }
+ } }
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
Canvas c = null;
try {
c = holder.lockCanvas(redrawRect);
- synchronized (holder) {
+ synchronized (holder) { synchronized (tiles) {
c.translate(screenOffset.x, screenOffset.y);
c.scale(scale, scale);
doDrawRect(c, area);
if (effect.displayText != null) {
drawEffectText(c, area, effect, textYOffset, textPaint);
}
- }
+ } }
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
int px = px0;
for (int x = 0; x < area.size.width; ++x, ++mx, px += tileSize) {
final int tile = layer.tiles[mx][my];
- if (tile != 0) {
- tiles.drawTile(canvas, tile, px, py, mPaint);
- }
+ if (tile == 0) continue;
+ tiles.drawTile(canvas, tile, px, py, mPaint);
}
}
}