Graphics
The Graphics object contains a set of methods that you can use to create a vector shape. Display objects that support drawing include Sprite and Shape objects. Each of these objects includes a graphics property that is a Graphics object. The following are among those helper functions provided for ease of use: drawRect(), drawRoundRect(), drawCircle(), and drawEllipse().
You cannot create a Graphics object directly from Lua Script code. If you call new Graphics(), an exception is thrown.
Created Graphics object has methods:
beginBitmapFill(bitmap, matrix, repeat, smooth) |
Fills a drawing area with a bitmap image. |
bitmap - A transparent or opaque bitmap image that contains the bits to be displayed. (BitmapData) matrix - (default = nil) - A matrix object, which you can use to define transformations on the bitmap. For example, you can use the following matrix to rotate a bitmap by 45 degrees (pi/4 radians): matrix = Lib.Media.Geom.Matrix.new(1,0,0,1,0,0) matrix.rotate(math.pi / 4) repeat - (default = true) - If true, the bitmap image repeats in a tiled pattern. If false, the bitmap image does not repeat, and the edges of the bitmap are used for any fill area that extends beyond the bitmap. smooth - (default = false) - If false, upscaled bitmap images are rendered by using a nearest-neighbor algorithm and look pixelated. If true, upscaled bitmap images are rendered by using a bilinear algorithm. Rendering by using the nearest neighbor algorithm is faster. |
beginFill(color, alpha) |
Specifies a simple one-color fill that subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) use when drawing. |
color - The color of the fill (0xRRGGBB). alpha - (default = 1.0) - The alpha value of the fill (0.0 to 1.0). |
beginGradientFill(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio) |
Specifies a gradient fill used by subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) for the object. |
type - A value from the GradientType object that specifies which gradient type to use: GradientType.LINEAR or GradientType.RADIAL. colors - An array of RGB hexadecimal color values used in the gradient; for example, red is 0xFF0000, blue is 0x0000FF, and so on. You can specify up to 15 colors. For each color, specify a corresponding value in the alphas and ratios parameters. alphas - An array of alpha values for the corresponding colors in the colors array; valid values are 0 to 1. If the value is less than 0, the default is 0. If the value is greater than 1, the default is 1. ratios - An array of color distribution ratios; valid values are 0-255. This value defines the percentage of the width where the color is sampled at 100%. The value 0 represents the left position in the gradient box, and 255 represents the right position in the gradient box. Note: This value represents positions in the gradient box, not the coordinate space of the final gradient, which can be wider or thinner than the gradient box. Specify a value for each value in the colors parameter. matrix - (default = nil) - A transformation matrix. The Matrix object includes a createGradientBox() method, which lets you conveniently set up the matrix for use with the beginGradientFill() method. spreadMethod - (default = "pad") - A value from the SpreadMethod object that specifies which spread method to use, either: SpreadMethod.PAD, SpreadMethod.REFLECT, or SpreadMethod.REPEAT. interpolationMethod - (default = "rgb") - A value from the InterpolationMethod object that specifies which value to use: InterpolationMethod.LINEAR_RGB or InterpolationMethod.RGB focalPointRatio - (default = 0) - A number that controls the location of the focal point of the gradient. 0 means that the focal point is in the center. 1 means that the focal point is at one border of the gradient circle. -1 means that the focal point is at the other border of the gradient circle. A value less than -1 or greater than 1 is rounded to -1 or 1. |
clear() |
Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. |
|
curveTo(controlX, controlY, anchorX, anchorY) |
Draws a quadratic Bezier curve using the current line style from the current drawing position to (anchorX, anchorY) and using the control point that (controlX, controlY) specifies. |
controlX - A number that specifies the horizontal position of the control point relative to the registration point of the parent display object. controlY - A number that specifies the vertical position of the control point relative to the registration point of the parent display object. anchorX - A number that specifies the horizontal position of the next anchor point relative to the registration point of the parent display object. anchorY - A number that specifies the vertical position of the next anchor point relative to the registration point of the parent display object. |
drawCircle(x, y, radius) |
Draws a circle. |
x - The x location of the center of the circle relative to the registration point of the parent display object (in pixels). y - The y location of the center of the circle relative to the registration point of the parent display object (in pixels). radius - The radius of the circle (in pixels). |
drawEllipse(x, y, width, height) |
Draws an ellipse. |
x - The x location of the top-left of the bounding-box of the ellipse relative to the registration point of the parent display object (in pixels). y - The y location of the top left of the bounding-box of the ellipse relative to the registration point of the parent display object (in pixels). width - The width of the ellipse (in pixels). height - The height of the ellipse (in pixels). |
drawGraphicsData(graphicsData) |
Submits a series of IGraphicsData instances for drawing. |
graphicsData - Vector array of IGraphicsData - A Vector containing graphics objects, each of which much implement the IGraphicsData interface. |
drawPath(commands, data, winding) |
Submits a series of commands for drawing. |
commands - A Vector array of integers representing drawing commands. The set of accepted values is defined by the constants in the GraphicsPathCommand object. data - A Vector array of Number instances where each pair of numbers is treated as a coordinate location (an x, y pair). The x- and y-coordinate value pairs are not Point objects; the data vector is a series of numbers where each group of two numbers represents a coordinate location. winding - (default = "evenOdd") - Specifies the winding rule using a value defined in the GraphicsPathWinding object. |
drawRect(x, y, width, height) |
Draws a rectangle. |
x - A number indicating the horizontal position relative to the registration point of the parent display object (in pixels). y - A number indicating the vertical position relative to the registration point of the parent display object (in pixels). width - The width of the rectangle (in pixels). height - The height of the rectangle (in pixels). |
drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight) |
Draws a rounded rectangle. |
x - A number indicating the horizontal position relative to the registration point of the parent display object (in pixels). y - A number indicating the vertical position relative to the registration point of the parent display object (in pixels). width - The width of the round rectangle (in pixels). height - The height of the round rectangle (in pixels). ellipseWidth - The width of the ellipse used to draw the rounded corners (in pixels). ellipseHeight - The height of the ellipse used to draw the rounded corners (in pixels). Optional; if no value is specified, the default value matches that provided for the ellipseWidth parameter. |
drawTriangles(vertices, indices, uvtData, culling, colours, blendMode) |
Renders a set of triangles, typically to distort bitmaps and give them a three-dimensional appearance. |
vertices - A Vector array of Numbers where each pair of numbers is treated as a coordinate location (an x, y pair). The vertices parameter is required. indices - A Vector array of integers or indexes, where every three indexes define a triangle. If the indexes parameter is null then every three vertices (six x,y pairs in the vertices Vector) defines a triangle. Otherwise each index refers to a vertex, which is a pair of numbers in the vertices Vector. For example indexes[1] refers to (vertices[2], vertices[3]). The indexes parameter is optional, but indexes generally reduce the amount of data submitted and the amount of data computed. uvtData - A Vector array of normalized coordinates used to apply texture mapping. Each coordinate refers to a point on the bitmap used for the fill. You must have one UV or one UVT coordinate per vertex. In UV coordinates, (0,0) is the upper left of the bitmap, and (1,1) is the lower right of the bitmap. If the length of this vector is twice the length of the vertices vector then normalized coordinates are used without perspective correction. If the length of this vector is three times the length of the vertices vector then the third coordinate is interpreted as 't' (the distance from the eye to the texture in eye space). This helps the rendering engine correctly apply perspective when mapping textures in three dimensions. If the uvtData parameter is nil, then normal fill rules (and any fill type) apply. culling - (default = "none") - Specifies whether to render triangles that face in a specified direction. This parameter prevents the rendering of triangles that cannot be seen in the current view. This parameter can be set to any value defined by the TriangleCulling object. colours - array of colours (Int) blendMode - blend mode (BlendMode) |
endFill() |
Applies a fill to the lines and curves that were added since the last call to the beginFill(), beginGradientFill(), or beginBitmapFill() method. |
|
lineBitmapStyle(bitmap, matrix, repeat, smooth) |
Specifies a bitmap to use for the line stroke when drawing lines. |
bitmap - The bitmap to use for the line stroke. (BitmapData) matrix - (default = nil) - transformation matrix as defined by the Matrix object. The matrix can be used to scale or otherwise manipulate the bitmap before applying it to the line style. repeat - (default = true) - Whether to repeat the bitmap in a tiled fashion. smooth - (default = false) - Whether smoothing should be applied to the bitmap. |
lineGradientStyle(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio) |
Specifies a gradient to use for the stroke when drawing lines. |
type - A value from the GradientType object that specifies which gradient type to use, either GradientType.LINEAR or GradientType.RADIAL. colors - An array of RGB hex color values to be used in the gradient (for example, red is 0xFF0000, blue is 0x0000FF, and so on). alphas - An array of alpha values for the corresponding colors in the colors array; valid values are 0 to 1. If the value is less than 0, the default is 0. If the value is greater than 1, the default is 1. ratios - An array of color distribution ratios; valid values are from 0 to 255. This value defines the percentage of the width where the color is sampled at 100%. The value 0 represents the left position in the gradient box, and 255 represents the right position in the gradient box. This value represents positions in the gradient box, not the coordinate space of the final gradient, which can be wider or thinner than the gradient box. Specify a value for each value in the colors parameter. spreadMethod - (default = "pad") - A value from the SpreadMethod object that specifies which spread method to use. interpolationMethod - (default = "rgb") - A value from the InterpolationMethod object that specifies which value to use. For example, consider a simple linear gradient between two colors (with the spreadMethod parameter set to SpreadMethod.REFLECT). The different interpolation methods affect the appearance as follows: focalPointRatio - (default = 0) - A number that controls the location of the focal point of the gradient. The value 0 means the focal point is in the center. The value 1 means the focal point is at one border of the gradient circle. The value -1 means that the focal point is at the other border of the gradient circle. Values less than -1 or greater than 1 are rounded to -1 or 1. |
lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit) |
Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. |
thickness - An integer that indicates the thickness of the line in points; valid values are 0-255. If a number is not specified, or if the parameter is undefined, a line is not drawn. If a value of less than 0 is passed, the default is 0. The value 0 indicates hairline thickness; the maximum thickness is 255. If a value greater than 255 is passed, the default is 255. color - (default = 0) - A hexadecimal color value of the line; for example, red is 0xFF0000, blue is 0x0000FF, and so on. If a value is not indicated, the default is 0x000000 (black). alpha - (default = 1.0) - A number that indicates the alpha value of the color of the line; valid values are 0 to 1. If a value is not indicated, the default is 1 (solid). If the value is less than 0, the default is 0. If the value is greater than 1, the default is 1. pixelHinting - (default = false) - A Boolean value that specifies whether to hint strokes to full pixels. This affects both the position of anchors of a curve and the line stroke size itself. With pixelHinting set to true, line widths are adjusted to full pixel widths. With pixelHinting set to false, disjoints can appear for curves and straight lines. scaleMode - (default = "normal") - A value from the LineScaleMode object that specifies which scale mode to use: LineScaleMode.NORMAL - Always scale the line thickness when the object is scaled (the default). LineScaleMode.NONE - Never scale the line thickness. (not supported) LineScaleMode.VERTICAL - Do not scale the line thickness if the object is scaled vertically only. (not supported) LineScaleMode.HORIZONTAL - Do not scale the line thickness if the object is scaled horizontally only. (not supported) caps - A value from the CapsStyle object that specifies the type of caps at the end of lines. Valid values are: CapsStyle.NONE, CapsStyle.ROUND, and CapsStyle.SQUARE. If a value is not indicated, application uses round caps. joints - A value from the JointStyle object that specifies the type of joint appearance used at angles. Valid values are: JointStyle.BEVEL, JointStyle.MITER, and JointStyle.ROUND. If a value is not indicated, application uses round joints. Note: For joints set to JointStyle.MITER, you can use the miterLimit parameter to limit the length of the miter. miterLimit - (default = 3) - A number that indicates the limit at which a miter is cut off. Valid values range from 1 to 255 (and values outside that range are rounded to 1 or 255). This value is only used if the jointStyle is set to "miter". The miterLimit value represents the length that a miter can extend beyond the point at which the lines meet to form a joint. The value expresses a factor of the line thickness. |
lineTo(x, y) |
Draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y). |
x - A number that indicates the horizontal position relative to the registration point of the parent display object (in pixels). y - A number that indicates the vertical position relative to the registration point of the parent display object (in pixels). |
moveTo(x, y) |
Moves the current drawing position to (x, y). |
x - A number that indicates the horizontal position relative to the registration point of the parent display object (in pixels). y - A number that indicates the vertical position relative to the registration point of the parent display object (in pixels). |
drawTiles(sheet, xyid, smooth, flags, count) |
|
sheet - Tilesheet object xyid - array of Float values in order of X,Y,ID values smooth - Whether tiles should be smoothed while drawing(Recommended default: false) flags - Flags to enable scale, rotation, RGB and/or alpha when drawing(Recommended default: 0) count - data size, int (recommended default -1, means use all xyid positions) |
Created with the Personal Edition of HelpNDoc: Full-featured EBook editor