2011-11-19 58 views
2

我试图用画布比例缩放后的移动限制,但新的坐标不匹配。
我的宽度为480,在1.5f放大后,我的宽度将为720 ...但是当我将其设置为-480时,我在右侧看到更多空间。Android画布比例尺,翻译和位置

float zoom = 0.5f; 
PointF translate = new PointF(0, 0); 
canvas.scale(zoom, zoom); 
canvas.translate(translate.x, translate.y); 
//... 
canvas.drawRect(0, 0, width, height, paint); 

对不起我的英文不好和说明,但我想总结一下;
放大移动画布后,翻译的真实宽度/高度限制是多少?

+0

你有没有解决??请分享它..我面临这个问题.. :( –

+0

我发送我的方法 – musa

回答

1

我解决了这个问题如下:

(屏幕分辨率:800×480 [风景])

int screenWidth = 800; 
int gameLimitX = 1600; 
int cameraPositionX = 0; 

float zoom = 1.0; 

if((screenWidth/zoom) + cameraPositionX > gameLimitX) { 
    cameraPositionX = (screenWidth/zoom) + cameraPositionX; 
} 

(做相同的Y /高)
我希望你能理解。

0

您可以保存当前的变焦,然后乘以这样翻译:

canvas.scale(_factorScale, _factorScale); 
int wGameView = (int) (_wGameView/_factorScale); 
int hGameView = (int) (_hGameView/_factorScale); 
int xCam = (int) (ptCentre.x-(wGameView>>>1)); 
int yCam = (int) (ptCentre.y-(hGameView>>>1)); 
//move camera now! 
canvas.translate(-xCam,-yCam); 
//here goes drawing 
+0

我不明白。什么意思是ptCentre? – musa