有没有办法在Android中以下列模式绘制一个Rect,而不是“left,top,right,bottom”?问题是我使用的是随机坐标:
Rect e = new Rect(random.nextInt(300)+20,20,random.nextInt(300)+45,70);
并且很难跟踪第一个左侧随机位置以包含在右侧的宽度中。在“x,y,w,h”中,很容易应用我的碰撞测试:
if ((((p.left+p.width())>e.left)&&(p.left<(e.left+e.width())))&&
(((p.top+p.height())>e.top)&&(p.top<(e.top+e.height())))) {
gameScreen = 2;
}
答案 0 :(得分:1)
只需将随机数移到rect的构造函数之外。
int left = random.nextInt(300)+20;
int right = left + 20;
int top = random.nextInt(300)+45;
int bottom = top + 70;
Rect e = new Rect(left, top, right, bottom);