Results 1 to 4 of 4

Thread: IntersectRect?

  1. #1
    NOMADMAN
    Guest

    Question IntersectRect?

    I've searched this message board for a couple days and still don't get how the IntersectRect API works. I'm doing some simple rectangular collison detection and I don't understand the parameters of the API:

    Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long

    What does the Destination Rectangle do/look like?
    I've defined RECT (TOP,BOTTOM,LEFT,RIGHT as long) as a type, is that right?

    Here is all my object collision code:
    Code:
    Dim TempRect as RECT
    If IntersectRect(TempRect, BLOCKS(i).POINTS, BALLS(j).POINTS) <> 0 And BLOCKS(i).HIT > 0 Then
    TempRect is a dummy varible, it has no value unless IntersectRect gives it to it.
    .POINTS are defined as RECT...

    The ball just passes through the block, never "hitting" them.

    Anyone know what's wrong?

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Forget about that, use the good old VB function that NEVER gives you any problems

    VB Code:
    1. If Obj1.Right>=Obj2.Left And Obj1.Left<=Obj2.Right And Obj1.Bottom>=Obj2.Top And Obj1.Top<=Obj2.Bottom Then
    2.     'We've got a collision! :)
    3. End If
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3
    Zaei
    Guest
    API is faster, Jotaf. You can do anything in VB... its just a whole lot slower =).

    If you remove the "And Blocks..." part, it might work. What is that for?

    Also, a RECT is defined as:
    Code:
    Type RECT
        Left as Long
        Top as Long
        Right as Long
        Bottom as Long
    End Type
    This is actually very important. If you dont have it this way, change it, and it might solve your problem right there. Otherwise, your code looks fine.

    Z.

  4. #4
    NOMADMAN
    Guest
    Thank you. This is for a Breakout clone. I guess I have a problem somewhere else...

    Oh yeah, I had it declared like you said. I was just to lazy to post it like that.

    Thanks again for all your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width