1

I'm trying to make a Minesweeper game in android to practise using Canvas to draw images.

I'm currently using drawBitmap(image,x,y,antialiasPaint) but, when I resize the board and the tiles become so small, this occurs:

Image

You can see the black lines that appears sometimes between the tiles... I'm drawing each Tile object using this code.

/**
*   @param canvas Canvas directly from View's @Override draw(Canvas canvas)
*   @param parentX Parent X position
*   @param parentY Parent Y position
*/
public void draw(Canvas canvas, float parentX, float parentY){
    canvas.drawBitmap(base,parentX+x,parentY+y, paint);
}

Using a bufferedBitmap like this solves that problem, but it slows a lot the performance rathen than boosting it...

Maybe I'm not doing it well? I'm doing it like this:

private Canvas c = new Canvas();
private Bitmap bufferedImage;
public void zoom(float z){
    this.scale *= z;
    this.scale = Math.max(0.3f, Math.min(scale, 1f));
    this.vWidthScaled = vWidth/scale;
    this.vHeightScaled = vHeight/scale;
    bufferedImage = Bitmap.createBitmap((int)vWidthScaled, (int)vHeightScaled, Bitmap.Config.ARGB_8888);
}

@Override
public void draw(Canvas canvas){
    c.setBitmap(bufferedImage);
    grid.draw(c, vWidthScaled, vHeightScaled);

    canvas.drawColor(TileStyle.getInstance().getBackgroundColor());
    canvas.scale(scale, scale);
    canvas.drawBitmap(bufferedImage,0,0,null);
    canvas.scale(1/scale, 1/scale);
}

Is there any other solution I can use to solve this?

Scop
  • 11
  • 1

0 Answers0