Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a function that takes a seamless bitmap and scrolls it on the screen in any direction using world coordinates. There are 4 draws (play area is smaller than the full bitmap size.. So at the most, you'll see 4 copies of the bitmap, just different sections drawn to retain the seamless effect). What I want to know is, should I apply modifications to the rect bounds so that it's only blitting the parts that it should onto the screen? Or should I let Android handle that? And if I do it myself, how should I handle that? The world coordinates and translate really confuse me, as far as the math goes. :/

Here's 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();
}
like image 851
Salx Avatar asked Nov 05 '22 14:11

Salx


1 Answers

I'm not sure I understand the details of the code chunk you've posted, but if you're asking does android clip draws to the screen bounds automatically the answer is yes. So you don't have to set bounds when drawing your bitmap unless you want to draw a portion of it smaller than the screen.

like image 146
Matt Hall Avatar answered Nov 09 '22 15:11

Matt Hall