对于使用简单 (x,y) 坐标绘制的位图,
float _x = x - (bitmap.getWidth() / 2);
float _y = y - (bitmap.getHeight() / 2);
canvas.drawBitmap(bitmap, _x, _y, null);
我可以检测位图是否被触摸。
我正在用
dest = new Rect(0,0,0,0);
src = new Rect(0,0,0,0);
mSpriteHeight = (int) (sprite_pixel_height * mScale + 0.5f);
mSpriteWidth = (int) (sprite_pixel_width * mScale + 0.5f);
src.top = 0;
src.left = 0;
src.bottom = mSpriteHeight;
src.right = mSpriteWidth;
dest.top = (int) (_x * mScale);
dest.bottom = (int) ((_x + mSpriteHeight) * mScale);
dest.left = (int) (_y * mScale);
dest.right = (int) ((_y + mSpriteWidth) * mScale);
canvas.drawBitmap(bitmap, src, dest, null);
试图合并 屏幕密度,因为“此函数忽略与位图相关的密度。......所以必须已经应用了适当的缩放因子。”
我无法检测到对翻译位图的触摸。我必须使用 进行类似的翻译mScale
,但我迷路了。
有没有更好的方法来定义我原来的 src 和 dest canvas.drawBitmap(bitmap, src, dest, null);
?
有人知道这样做的例子吗?我似乎找不到合适的搜索词来找到这样的例子。