0%

Drawing interface

Client drawing interface lua layer function, mainly on SDL global table.

Auxiliary classes, introduction to Color, Point, Rect, Points, and Rects

SDL.Color -> represents the RGB color class

1. local c = SDL.Color() -> Construct a bit-initialized Color object
  1. c.r=255; c.g=255; c.b=255; c.a=255; -> Assign a value to the color object, r red, g green, b blue, a transparency, 255 bits are opaque, and 0 bits are completely transparent. An opaque white color is defined here.
  2. local c = SDL.Color.new(r,g,b,a) -> directly generate a color object using numerical values, ranging from 0 to 255

SDL.Point -> Point class

1. local p = SDL.Point() -> Construct a bit-initialized point object
  1. p.x=100; c.y=200; -> Assign value to point object
  2. local p = SDL.Point.new(x,y) -> directly generate a point object using numerical values

SDL.Rect -> Holding area

1. local r = SDL.Rect() -> Construct a bit-initialized holding object
  1. r.x=100; r.y=200; r.w=50; r.h=30; -> Assign a value to the holding object, x, y holds the coordinates of the upper left corner, w holds the width, h holds the height
  2. local r = SDL.Rect.new(x,y,w,h) -> directly use the numerical value to generate a holding object

SDL.Points -> Array collection of point objects

1. local ps = SDL.Points() -> Construct an empty point array collection
2. ps:push(p) -> Put the point object into the point array collection, the parameter p is the generated point object
3. ps:pop() -> Pop an element from the end of the collection
4. ps:clear() -> Clear the collection
5. ps:size() -> Get the number of elements in the collection
6. ps:empty() -> Determine whether the collection is empty, return true if empty

SDL.Rects -> Array collection holding objects

1. local rs = SDL.Rects() -> Construct an empty array collection
2. rs:push(r) -> Put the hold object into the hold array collection, and the parameter r is the generated hold object
3. rs:pop() -> Pop an element from the end of the collection
4. rs:clear() -> Clear the collection
5. rs:size() -> Get the number of elements in the set
6. rs:empty() -> Determine whether the set is empty, return true if empty

Create various graphic objects, these methods are on the management class returned by SDL.mgr.getInstance()

1. SDL.mgr.getInstance():createPoint(x,y,c) -> Draw a pixel on the screen, x,y coordinates, c color object, return return value Node created display object
2. SDL.mgr.getInstance():createLine(x1,y1,x2,y2,c) -> Draw a pixel line on the screen, x1,y1 are the starting point of the line, x2,y2 are the end point of the line, c is the color object, return return value Node created display object
  1. SDL.mgr.getInstance():createRect(x,y,w,h,fill,c) -> Draw a hold on the screen. The coordinates of the upper left corner are held by x and y, and the width and height are held by w and h. , if fill is true, the entire hold will be filled with color c, if false, the border of the hold will be drawn with color c, c color object, return value The display object created by Node
  2. SDL.mgr.getInstance():createPoints(points,c) -> Draw multiple pixels on the screen. points is a point collection object, including multiple points, c is a color object, and returns the return value of the display object created by Node.
    1. SDL.mgr.getInstance():createLines(points,c) -> Draw multiple straight lines on the screen. They are connected end to end according to the order of the points. There must be two points in the point array set, otherwise an error will be reported, points Point array collection, must be greater than or equal to 2, c color object, return return value Node created display object
  3. SDL.mgr.getInstance():createRects(rects,fill,c) -> Draw multiple objects on the screen. The rects object is an array collection. If fill is true, the entire object will be filled with c color. If it is false, it will be filled with c color. Draw the held border, c color object, return return value Node created display object
  4. SDL.mgr.getInstance():createImage(path,x,y,w,h) -> Display a picture on the screen, path is the resource path where the picture is located, supports jpg\png, etc., x,y is the picture displayed The position of the upper left corner of the object, the length and width of the object to be displayed by w and h, and the weak image size does not match the displayed holding parameters. The image will be scaled to adapt to the given coordinate holding size, and the return value is the display object created by Node.
  5. SDL.mgr.getInstance():createText(text,x,y,c) -> Display a line of text on the screen, text is the text to be displayed, supports Chinese, x,y displays the upper left corner position of the text, c color Object, return return value Display object created by Node
  6. SDL.mgr.getInstance():createCircle(x,y,radius,fill,c) -> Create a circle x, the center point of the y circle, the radius of the radius circle, whether fill fills the circle, c color object, return Return value The display object created by Node
  7. SDL.mgr.getInstance():createLayer(x,y,w,h,c) -> Create a container panel, which can add various sub-objects or nest panels, x,y,w,h It has the same meaning as holding, it can only fill the background color with color, c color object, return return value Node created display object

Common method for creating graphics objects (SDLNode) parent class

  1. node:movePosition(x,y) -> Translate the current node object, x|y is the logical pixel to be translated. When the node object is SDLLayer, the sub-objects will move together. SDLRoot and object mgr cannot be moved.
  2. node:changePosition(x,y) -> Set the current node object to the center coordinate, the logical pixel coordinate to be set in x|y. When the node object is SDLLayer, the sub-objects will be set together. SDLRoot and object mgr cannot be set.
    3.node:changeValue(text) -> When node is a label text label, change the text.
  3. node:changeColor(r,g,b,a) -> Change the initial color of the graphic. r,g,b,a are the numerical value of rgb color and a transparency respectively.
  4. node:getPoints() -> Get the internal collection of Points and Lines graphics, and the modifications will be fed back to the screen from time to time.
  5. node:getRects() -> Get the internal collection of Rects graphics, and modifications will be fed back to the screen from time to time.

Put the display object on the screen. The object returned by SDL.mgr.getInstance() is actually the top-level node object, and the object returned by createLayer is the container object. They have the same management level method.

For the convenience of description, the top-level object is called mgr, the panel object created by createLayer is called layer, and the other display objects created are called node node objects.

  1. mgr:add(o,z) and layer:add(o,z) -> Put the display object into the panel, o displays the object, or it can be the display panel. When the display object enters its panel or the top-level panel, Its coordinates are offset from the relative coordinates of its panel; z is the order in which display objects on the same layer are drawn. The smaller the number, the lower the priority. The image drawn later will overwrite the image drawn before. return value The unique ID of the display object. For example:
    1
    2
    3
    4
    5
    local mgr = mgr.getInstance() -- save the top-level management object
    local layer = mgr:createLayer(10,10,100,30,SDL.Color.new(0,0,255,255)) -- Created a container panel with a blue background
    local text = mgr:createText("",10,8,SDL.Color.new(0,0,0,255))
    mgr:add(layer,0) -- Put the panel on top
    layer:add(text,0) -- put text into the panel
    At this time, the coordinate panel layer is relative to the top mgr00 point, and the text text is relative to its panel coordinate layer 1010.
  2. mgr:remove(id) and layer:remove(id) -> Delete the display object in the container. The id is the unique identifier returned by add, which can also be obtained through the id attribute of the created Node object.
  3. mgr:get(id) and layer:get(id) -> Get the specified display object Node in the container through the ID
  4. mgr:clear() and layer:clear() –> Clear all display elements in the container

Other relevant information

  1. The current logical width and height pixel dimensions of the screen can be obtained through SDL.dwidth and SDL.dheight. This property is a read-only property. Please do not assign a value. It is currently 720*1280.
  2. The current resolution size of the screen can be obtained through SDL.width and SDL.height. This property is a read-only property. When drawing, please pay attention to the above logical size, which can also be said to be the design size. If the logical size and the resolution size are different, the engine will automatically scale to the screen display that combines the current resolution. The rule is the maximum scaling of the long side.
  3. SDL.setLogicScreenSize(w,h) -> Modify the rendering logical pixel size. After modification, dwidth and dheight will change together, but the screen pixel size will not change.
  4. Every time you start or end the game, you can call mgr:clear() to clear all displays.
  5. Please do not select a value less than 0 for the second parameter of the add method to avoid overwriting the system menu display and dialog box.
  6. The font is now Microsoft Yahei by default. You need to adjust the font and wait for the next interface.