Category: 2D Overlay
Syntax:
b2dSetClipRect:Void(x:Int, y:Int, width:Int, height:Int)
Void
Restricts subsequent drawing to a rectangular region - a 2D scissor.
Takes x, y (top-left corner of the clip region, in pixels) and width, height (its
size). Everything drawn afterwards is confined to that rectangle until
b2dClearClipRect is called, or until another b2dSetClipRect replaces it.
Returns nothing.
It applies to primitives, images and text alike - every 2D draw goes
through the same scissor.
It is ordered. Draws made before the call are not clipped; only
those made after it are. That is what makes it useful per-object: set the clip,
draw the thing that needs cutting off, clear it again.
Coordinates are in the current render target's space - the same space
b2dDrawRect and the rest use. On screen that is the resolution you asked
b2dGraphics for, whatever size the window or monitor actually is.
The rectangle is clamped to the target, so one that hangs over an edge simply
draws less; one entirely outside it draws nothing at all. A width or height of
zero or less also draws nothing.
The clip is cleared at the start of every frame. Forgetting to clear one
costs you the rest of that frame, not every frame afterwards.
Uses include cutting a sprite off at an opening (an enemy seen through a low
tunnel shows only its legs), HUD panels, minimap framing, split-screen regions,
and text that must not overflow its box.
View detailed documentation online
; Only the part of the sprite inside the gap is drawn b2dSetClipRect(0, gapY, 640, 480 - gapY) b2dDrawImage(enemy, ex, ey) b2dClearClipRect()
BambooBasic © 2026 Michael Denathorn