graphics.drawRectangle
Jump to navigation
Jump to search
Function Client Only
![]()
Online and Offline
Available since Client 1.0.0
void graphics.drawRectangle(Surface surface, Vec2 position, Vec2 size, [ int colour1 = COLOUR_WHITE ], [ int colour2 = COLOUR_WHITE ], [ int colour3 = COLOUR_WHITE ], [ int colour4 = COLOUR_WHITE ], [ float rotation = 0.0 ], [ Vec2 center = Vec2(0.0,0.0) ], [ Vec2 sourcePos = Vec2(0.0,0.0) ], [ Vec2 sourceSize = Vec2(1.0,1.0) ], [ Vec2 scale = Vec2(1.0,1.0) ])
The graphics.drawRectangle function is used to draw an image or coloured rectangle in 2D space.
Parameters
| 1) | Surface | surface | The surface object. Use an image, or null to draw a colored rectangle. |
| 2) | Vec3 | position | The position in the game window for the rectangle in a Vector2 (x,y) format. Measured in pixels. |
| 3) | Vec3 | size | The size of the rectangle in a Vector2 (x,y) format. Measured in pixels. |
| 4) | int | colour1 | Optional, defaults to COLOUR_WHITE. The 1st colour for the rectangle, created by toColour. |
| 5) | int | colour2 | Optional, defaults to COLOUR_WHITE. The 2nd colour for the rectangle, created by toColour. |
| 6) | int | colour3 | Optional, defaults to COLOUR_WHITE. The 3rd colour for the rectangle, created by toColour. |
| 7) | int | colour4 | Optional, defaults to COLOUR_WHITE. The 4th colour for the rectangle, created by toColour. |
| 8) | float | rotation | Optional, defaults to 0.0. The rotation of the rectangle. |
| 9) | Vec2 | center | Optional, defaults to Vec2(0.0,0.0). The center of the rectangle. |
| 10) | Vec2 | sourcePos | Optional, defaults to Vec2(0.0,0.0). A position inside the image source in the Surface arg. |
| 11) | Vec2 | sourceSize | Optional, defaults to Vec2(1.0,1.0). A size inside the image source in the Surface arg. |
| 12) | Vec2 | scale | Optional, defaults to Vec2(1.0,1.0). The scale of the source image. |
Return
| void | This function doesn't return a value. |
Notes
- The sourcePos, sourceSize, and scale args can be used to set which part of an image is shown in the rectangle. Useful if you have a large image of sprites (sprite-sheet) or just want to render a certain part of an image instead of the entire thing.
- Using multiple different colours in the colour 1-4 args will draw the rectangle with a gradient. Using only 1 colour arg, or making all the same colour will draw a solid colour.Rectangles can be drawn with transparency via the 4th arg (alpha) in toColour.
Examples
There aren't any examples for this function.
Compatibility
There isn't any compatibility information for this function.