【发布时间】:2011-11-19 20:11:36
【问题描述】:
我有一个功能,它采用无缝位图并使用世界坐标在屏幕上向任何方向滚动它。有 4 次绘制(播放区域小于完整的位图大小。所以您最多会看到 4 个位图副本,只是绘制了不同的部分以保持无缝效果)。我想知道的是,我应该对矩形边界进行修改,以便它只将它应该在屏幕上显示的部分吗?还是我应该让 Android 来处理? 如果我自己做,我应该如何处理?就数学而言,世界坐标和翻译真的让我很困惑。 :/
这是代码。
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();
}
【问题讨论】:
标签: java android math optimization