graphics.drawRectangle: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
|type = function | |type = function | ||
|name = graphics.drawRectangle | |name = graphics.drawRectangle | ||
|usage = draw | |usage = draw an image or coloured rectangle in 2D space | ||
|parameters = 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) ] | |parameters = 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) ] | ||
|parameter1 = Surface surface The surface object, | |parameter1 = Surface surface The surface object. Use [[graphics.loadPNG|an image]], or null to draw a colored rectangle. | ||
|parameter2 = Vec3 position The | |parameter2 = Vec3 position The position in the game window for the rectangle in a Vector2 (x,y) format. Measured in pixels. | ||
|parameter3 = Vec3 size The | |parameter3 = Vec3 size The size of the rectangle in a Vector2 (x,y) format. Measured in pixels. | ||
|parameter4 = int colour1 optional COLOUR_WHITE The 1st colour for the rectangle. | |parameter4 = int colour1 optional COLOUR_WHITE The 1st colour for the rectangle, created by [[toColour|toColour]]. | ||
|parameter5 = int colour2 optional COLOUR_WHITE The 2nd colour for the rectangle. | |parameter5 = int colour2 optional COLOUR_WHITE The 2nd colour for the rectangle, created by [[toColour|toColour]]. | ||
|parameter6 = int colour3 optional COLOUR_WHITE The 3rd colour for the rectangle. | |parameter6 = int colour3 optional COLOUR_WHITE The 3rd colour for the rectangle, created by [[toColour|toColour]]. | ||
|parameter7 = int colour4 optional COLOUR_WHITE The 4th colour for the rectangle. | |parameter7 = int colour4 optional COLOUR_WHITE The 4th colour for the rectangle, created by [[toColour|toColour]]. | ||
|parameter8 = float rotation optional 0.0 The rotation of the rectangle. | |parameter8 = float rotation optional 0.0 The rotation of the rectangle. | ||
|parameter9 = Vec2 center optional Vec2(0.0,0.0) The center of the rectangle. | |parameter9 = Vec2 center optional Vec2(0.0,0.0) The center of the rectangle. | ||
|parameter10 = Vec2 sourcePos optional Vec2(0.0,0.0) | |parameter10 = Vec2 sourcePos optional Vec2(0.0,0.0) A position inside the image source in the Surface arg. | ||
|parameter11 = Vec2 sourceSize optional Vec2(1.0,1.0) | |parameter11 = Vec2 sourceSize optional Vec2(1.0,1.0) A size inside the image source in the Surface arg. | ||
|parameter12 = Vec2 scale optional Vec2(1.0,1.0) The scale of the | |parameter12 = Vec2 scale optional Vec2(1.0,1.0) The scale of the source image. | ||
|return1 = void | |return1 = void | ||
|returnFail1 = void | |returnFail1 = void | ||
|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.<br> | |||
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|toColour]] | |||
}} | }} | ||
Latest revision as of 23:23, 5 December 2025
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.