ImageRectOverlap ( image,x,y,rect_x,rect_y,rect_width,rect_height )

Parameters

image - image to test

x - x position the image is drawn at

y - y position the image is drawn at

rect_x - x coordinate of the rectangle's top left corner

rect_y - y coordinate of the rectangle's top left corner

rect_width - width of the rectangle in pixels

rect_height - height of the rectangle in pixels

Description

Returns True if an image's rectangle overlaps a given rectangle.

A bounding-box test between a sprite and an area. Transparent pixels count, so the whole frame of the image is treated as solid - fast, and fine for blocky art or generous hot spots.

Typical uses are screen regions rather than objects: is the pointer over this menu entry, has the player entered the exit zone, is this enemy still inside the play area. Pass the same x,y you would pass to DrawImage and the image's handle is accounted for; the rectangle is a corner plus a width and height.

There is no frame parameter - the image's size always comes from frame 0. When you need the sprite's real shape to matter, use ImageRectCollide, which walks the pixels and takes a frame. If neither side of the test is really an image, RectsOverlap is simpler and faster still.

See also: ImageRectCollide, RectsOverlap, ImagesOverlap, ImagesCollide.

Example

; ImageRectOverlap Example
; ------------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

player=LoadImage("media/player.bmp")

px=100
py=100

While Not KeyDown(1)

    Cls

    ; Arrow keys steer the ship
    If KeyDown(203) Then px=px-3
    If KeyDown(205) Then px=px+3
    If KeyDown(200) Then py=py-3
    If KeyDown(208) Then py=py+3

    ; ImageRectOverlap tests the ship's bounding box against a screen
    ; rectangle (a 'hot spot') - fast, but transparent pixels count too
    hit=ImageRectOverlap(player,px,py,250,180,140,120)

    ; Draw the hot zone - red while the ship overlaps it
    If hit Then
        Color 255,60,60
    Else
        Color 80,200,80
    End If
    Rect 250,180,140,120,False
    DrawImage player,px,py

    Text 0,0,"Arrow keys: fly the ship into the zone   Esc: exit"
    Text 0,20,"ImageRectOverlap(player,"+px+","+py+",250,180,140,120)="+hit

    Flip

Wend

End

Index