how use IntersectRect()?
Dec 22, 2017 at 5:53pm UTC
how can i use the IntersectRect() for i get the collision effect?
1 2 3 4 5 6 7 8 9 10 11
bool Collision(RECT rect1, RECT rect2)
{
if (IntersectRect(NULL,&rect1, &rect2))
{
// collision detected!
return true ;
}
else
return false ;
}
i always get false. i don't understand why
Dec 22, 2017 at 6:08pm UTC
Are you using it inside a while-Loop? If no, it might happen that if the procedure gets executed until the collision hasn't happened, that "false" is returned.
Dec 22, 2017 at 6:19pm UTC
i miss something on 'for':
1 2 3 4 5 6 7 8 9 10
RECT rectPlayer{sprPlayer.x, sprPlayer.y, sprPlayer.x+sprPlayer.width, sprPlayer.y+sprPlayer.height};
for (int i=0; i<10; i++)
{
if (sprDiamond[i].visible==false ) continue ;
RECT rectDiamonds={sprDiamond[i].x, sprDiamond[i].y, sprDiamond[i].x+sprDiamond[i].width,sprDiamond[i].y+ sprDiamond[i].height};
if (Collision(rectPlayer, rectDiamonds)==true )
{
sprDiamond[i].visible=false ;
}
}
now works fine.
but the player size can be wrong. i must test the size.
thank you so much
Topic archived. No new replies allowed.