Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check intersection in libgdx? [closed]

I have two sprites with two textures. How to check if they are intersecting ? I am using libgdx 0.9.8.

like image 901
user40713 Avatar asked Dec 14 '22 22:12

user40713


1 Answers

if (sprite1.getBoundingRectangle().contains(Sprite2.getBoundingRectangle())
{
    //gives true when sprite2 one is completly inside sprite1
}

also

if(sprite1.getBoundingRectangle().overlaps(Sprite2.getBoundingRectangle())
{
    // gives true when sprite 2 intersects sprite1
}
like image 154
Kumar Saurabh Avatar answered Dec 31 '22 21:12

Kumar Saurabh