简体   繁体   English

Android canvas使用canvas.scale翻转

[英]Android canvas flipping with canvas.scale

I have a little question. 我有一个小问题。 :) In my new live wallpaper I am flipping the canvas horizontally with: :)在我的新动态壁纸中,我使用以下命令水平翻转画布:

c.scale(-1f, 1f, screenWidth* 0.5f, screenHeight* 0.5f);
drawFlipped();
c.scale(-1f, 1f, screenWidth* 0.5f, screenHeight* 0.5f);

This all works great but I also happen to have an ontouch event where the user can click the different moving object defined as a Rect. 这一切都很好,但我碰巧也发生了ontouch事件,用户可以单击定义为Rect的其他移动对象。

But when the rect is drawn on the flipped canvas the x,y coordinates are not correct. 但是,当在矩形翻转的画布上绘制矩形时,x,y坐标不正确。 Its still in mirror and I understand that because I flip the canvas back after drawing the sprites. 它仍然在镜子中,我理解这是因为在绘制精灵后将画布翻转回去。

My question is: How can I calculate the on touch event from the right side of the screen? 我的问题是:如何从屏幕右侧计算触摸事件? I tried: Screenwidth - object.x - object.width but it did not help much :( 我试过了:Screenwidth-object.x-object.width但它并没有太大帮助:(

This works for me: 这对我有用:

int screenWidth = getScreenWidth();
Rect newCoordinates = new Rect(object.getRect()); //copies old coordinates
newCoordinates.right = screenWidth - object.getRect().left; //switch right and left since the Rect is being mirrored
newCoordinates.left = screenWidth - object.getRect().right;
object.setRect(newCoordinates);

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

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