Interface administrators, moderator
2,813
edits
No edit summary |
No edit summary |
||
| 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, created by [[toColour|toColour]]. | |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, created by [[toColour|toColour]]. | |parameter5 = int colour2 optional COLOUR_WHITE The 2nd colour for the rectangle, created by [[toColour|toColour]]. | ||
| Line 14: | Line 14: | ||
|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]] | |||
}} | }} | ||