Java – Should I rely on Android to discard off-screen drawing?

Should I rely on Android to discard off-screen drawing?… here is a solution to the problem.

Should I rely on Android to discard off-screen drawing?

I have a function that takes a seamless bitmap and scrolls it in any direction on the screen using world coordinates. There are 4 draws (the playback area is smaller than the entire bitmap size.) So at most, you’ll see 4 copies of the bitmap, just drawing different parts to keep the effect seamless). What I’m wondering is, should I modify the rectangle border so that it only shows the part that should be on the screen? Or should I let Android handle it?
What should I do if I do it myself? As far as mathematics goes, world coordinates and translation really confuse me. :/

Here is the code.

public void draw(Canvas canvas){

oCoords.x=(int) fX;
oCoords.y=(int) fY;

oTopLeft = gridContainingPoint(oCoords);
oTopRight.x = gridContainingPoint(oCoords).x + iWidth;
oTopRight.y = gridContainingPoint(oCoords).y;
oBottomLeft.x = gridContainingPoint(oCoords).x;
oBottomLeft.y = gridContainingPoint(oCoords).y + iHeight;
oBottomRight.x = gridContainingPoint(oCoords).x + iWidth;
oBottomRight.y = gridContainingPoint(oCoords).y + iHeight;

canvas.save();
canvas.translate(-fX, -fY);
oCloud.setBounds(oTopLeft.x, oTopLeft.y, oTopLeft.x + this.iImageWidth, oTopLeft.y + this.iImageHeight);
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x + this.iImageWidth, oTopLeft.y, oTopLeft.x + (this.iImageWidth * 2), oTopLeft.y + this.iImageHeight);
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x, oTopLeft.y + this.iImageHeight, oTopLeft.x + this.iImageWidth, oTopLeft.y + (this.iImageHeight * 2));
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x + this.iImageWidth, oTopLeft.y + this.iImageHeight, oTopLeft.x + (this.iImageWidth * 2),oTopLeft.y + (this.iImageHeight * 2));
oCloud.draw(canvas);
canvas.restore();
}

Best Solution

I’m not sure I understand the details of the code block you posted, but if you ask if android clip automatically draws to screen boundaries, the answer is yes. Therefore, unless you want to draw a part smaller than the screen, you do not have to set boundaries when drawing a bitmap.

Related Problems and Solutions