mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Fix graphics errors when displaying map after a map transition. (Do not draw the same bitmap simultaneously on both the displayed canvas and the in-memory canvas for rendering the worldmap).
This commit is contained in:
@@ -111,10 +111,11 @@ public final class WorldMapController {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -128,9 +129,8 @@ public final class WorldMapController {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import android.graphics.Canvas;
|
||||
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) {
|
||||
|
||||
@@ -43,11 +43,4 @@ public class TileCutter {
|
||||
public void recycle() {
|
||||
if (recycle) tilesetImage.recycle();
|
||||
}
|
||||
|
||||
public static int measureBitmapWidth(Resources r, int resourceID) {
|
||||
Bitmap b = BitmapFactory.decodeResource(r, resourceID);
|
||||
int width = b.getWidth();
|
||||
b.recycle();
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public final class TileManager {
|
||||
public void loadPreloadedTiles(Resources r) {
|
||||
int maxTileID = tileCache.getMaxTileID();
|
||||
if (AndorsTrailApplication.DEVELOPMENT_VALIDATEDATA) {
|
||||
if (maxTileID >= preloadedTiles.bitmaps.length) {
|
||||
if (maxTileID > preloadedTiles.maxTileID) {
|
||||
L.log("ERROR: TileManager.preloadedTiles needs to be initialized with at least " + maxTileID + " slots. Application will crash now.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +101,10 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
|
||||
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)
|
||||
);
|
||||
@@ -178,11 +178,11 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
|
||||
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
|
||||
@@ -210,7 +210,7 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
|
||||
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);
|
||||
@@ -218,7 +218,7 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
|
||||
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
|
||||
@@ -303,9 +303,8 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user