Rect x,y,width,height[,solid]
Parameters
|
x - x coordinate of the rectangle's top-left corner y - y coordinate of the rectangle's top-left corner width - width in pixels height - height in pixels solid (optional) - 1 draws a filled rectangle (default); 0 draws just the one-pixel outline |
Description
|
Draws a rectangle in the current drawing colour, filled or as an outline. Rectangles cover a lot of ground in 2D games: health bars, menu panels, selection boxes, platforms, fades. Give the top-left corner and the size - note the second pair is width and height, not the opposite corner. It draws filled unless you pass 0 for solid, which gives just the outline. The colour comes from Color, coordinates respect Origin, and drawing is clipped to the Viewport. A classic trick: a health bar is two Rects - a dark filled one for the frame, a bright filled one on top whose width is scaled by current health. See also: Oval, Line, Color, Viewport. |
Example
; Rect Example ; ------------ Graphics 640,480,0,2 SetBuffer BackBuffer() health=75 While Not KeyDown(1) Cls ; Space damages the player, H heals If KeyHit(57) And health>0 Then health=health-10 If KeyHit(35) And health<100 Then health=health+10 If health<0 Then health=0 ; Filled Rect: the red health bar (2 pixels wide per point) Color 200,30,30 Rect 220,220,health*2,30,1 ; Outline Rect: the bar frame (solid flag 0) Color 255,255,255 Rect 218,218,204,34,0 Text 0,0,"Space: take damage H: heal Esc: exit" Text 0,20,"Rect 220,220,"+(health*2)+",30,1 (filled) Rect 218,218,204,34,0 (outline)" Text 300,260,health+" / 100" Flip Wend End
Index