how use IntersectRect()?

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
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.
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.