Issue
I'm trying to collide my ball1 to greengreen drawable. how can I determine the collision?
public boolean CheckCollisionred(View ballr,View rr_1,View rg_3) {
Rect R1 = new Rect(ballr.getLeft(), ballr.getTop(), ballr.getRight(), ballr.getBottom());
Rect R2 = new Rect(rr_1.getLeft(), rr_1.getTop(), rr_1.getRight(), rr_1.getBottom());
Rect R3 = new Rect(rg_3.getLeft(), rg_3.getTop(), rg_3.getRight(), rg_3.getBottom());
return R1.setIntersect(R2, R3);
}
@Override
public void run() {startballanimation();
if (CheckCollisionred()) {
Score++;
}else
Score--;
}
UPDATE: this is showing me error "Checkcollisionred() in main activity cannot be applied to expected parameters, Actual arguments"
edit: the problem is I have an image button that displays the drawables that I want to collide .
Solution
You can check This for Finding Collision of Two Views. You can add that drawable in any Imageview.
public boolean CheckCollision(View v1,View v2) {
Rect R1=new Rect(v1.getLeft(), v1.getTop(), v1.getRight(), v1.getBottom());
Rect R2=new Rect(v2.getLeft(), v2.getTop(), v2.getRight(), v2.getBottom());
return R1.intersect(R2);
}
You can Add drawable as src
<ImageView
android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"/>
Answered By - Chandan kushwaha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.