开发者

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(oCoo开发者_Go百科rds).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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜