简体   繁体   English

Android canvas缩放,翻译和放置

[英]Android canvas scale, translate and positing

I'm trying the moving limit after zoom with canvas scale, but new coordinates does not match. 我正在尝试使用画布比例缩放后的移动限制,但是新坐标不匹配。
my width 480, after 1.5f zooming my width will be 720... but when I set translate to -480, I'm seeing more space on the right. 我的宽度480,在进行1.5f缩放后,我的宽度将为720 ...但是当我将其设置为-480时,我会在右边看到更多空间。

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);

sorry my bad English and explanation, but I want to ask in summary; 对不起,我的英语不好和解释不好,但我想总结一下。
what is the true width/height limit for translate after zooming for moving the canvas? 缩放移动画布后平移的真正宽度/高度限制是多少?

I solved this problem as follows; 我如下解决了这个问题;

(screen resolution: 800x480 [landscape]) (屏幕分辨率:800x480 [横向])

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

float zoom = 1.0;

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

(do same for y/height) (对y / h进行相同操作)
I hope you can understand. 我希望你能够明白。

You can save your current zoom and then multiply translations like this: 您可以保存当前的缩放比例,然后按以下方式进行多次翻译:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM