[英]On Android, how to draw a Rect like pygame Rect? (x, y, w, h)
有什么辦法可以按照以下模式在Android中繪制Rect,而不是“左,上,右,下”? 問題是我正在使用隨機坐標:
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;
}
只需將隨機數移到構造函數的外部即可。
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.