displays allow you to display information
in SComputers, displays have the best optimization of all mods in the workshop
the colors for the display can be specified in the following formats: 0xRRGGBB, "rrggbb", "#rrggbb", sm.color.new(r, g, b)
indexing of the display starts from 0 and up to width/height - 1. however, if you "go beyond the margins" nothing happens, all content that goes beyond the boundaries of the display simply will not be rendered
if you do not have enough variety of sizes and resolutions of displays presented in the basic mod, you can use the "stretchable display" addon
note that if the color is not specified (nil), then all rendering methods will perceive it as white, except clear, which perceives nil as black
please note that the display renders the image using effects. and a large number of effects cause LAGS. despite the best optimization of displays in the workshop at the moment, displays still cause lags due to effects. you can use display.setOptimizationLevel(0-255) to set how similar colors the display can combine. The default value is 16. 0 is a perfect picture and 256 is a very bad picture. For the most part, this optimization only makes sense when using cameras
attention. if your display usage scenario does not involve rendering a full-color image, then it is better to disable optimization using: display.setOptimizationLevel(0) (this way the display will work faster)
component name - display
list of materials for the display (can be setted using display.setMaterial):
- material 0 - transparent (default for holographic displays, not supported on a regular display)
- material 1 - glowing (default for displays)
- material 2 - general block
- material 3 - smoothed (to work, you will need to enable the blur effect in the game graphics settings)
- material 4 - glowing (alternative)
- material 5 - transparent (alternative)
methods:
- display.get(x:number, y:number):number - returns the current color in the display buffer at the specified position as a number. the color is taken from the host display. color format: 0xRRGGBB
- display.setOptimizationLevel(0-255) - sets the value of how similar the adjacent pixels must be in order to be combined into 1 effect. 0 is a perfect picture, 255 is a very poor picture quality. the higher the value, the fewer effects the display will use with a large number of colors on the screen (default: 16)
- display.getOptimizationLevel(0-255) - returns the value set using display.setOptimizationLevel (default: 16)
- display.isAllow():boolean - returns true if this display can be used. returns false if it was disabled by the administrator
- display.getAudience():number - returns the number of players who are currently looking at the display
- display.setFontScale(scaleX:float, scaleY:float) - allows you to stretch and compress the font. fractional values are allowed (by default 1, 1)
- display.setFontSize(charX:number, charY:number) - calculates font scaling based on the required size. please note that the calculation may not always be accurate with non-monospaced fonts
- display.getFontScale():float, float - returns the value set using display.setFontScale (by default 1, 1)
- display.setTextSpacing(number) - sets the distances between characters in pixels (by default 1)
- display.getTextSpacing():number - returns the value set using display.setTextSpacing (by default 1)
- display.calcTextBox(text:string):number, number - it will return two numbers, this will be the size of the box that your text will occupy with this font and this scale
- display.calcCharsSize(text:string):lens - calculates the length of each character in a string, taking into account its spacing from the next character, and returns a table with these values
- display.calcDecreasingTextSizes(text:string):lens - it works almost like display.calcCharsSize. however, each value contains all the previous ones. this is used in the graphic.textBox function, but probably not applicable to any other
- display.getWidth():number - returns the width of the display in pixels
- display.getHeight():number - returns the height of the display in pixels
- display.getSize():number, number - returns the width and height of the display
- display.getResolution():number, number - alias to display.getSize
- display.setUtf8Support(state:boolean) - set to true if you want to use Russian or other special characters which take up more than one byte (default: false)
- display.getUtf8Support():boolean - returns the value set using display.setUtf8Support (default: false)
- display.setRenderAtDistance(state:boolean) - allows you to see the contents of the display much further than it is usually visible (requires enable in the mod config) (default: false)
- display.getRenderAtDistance():boolean - returns the value set using display.setRenderAtDistance (default: false)
- display.setRotation(rotation:number) - programmatically rotates images onto displays. options 0, 1, 2, 3 are allowed. note that in modes 1 and 3, width and height are swapped (including the behavior of the display.getWidth, display.getHeight methods) (default: 0)
- display.getRotation():number - returns the value set using display.setRotation (default: 0)
- display.setFont(font) - sets a custom font. if the font is from the "fonts library", it will not be transmitted over the network. however, if it is a custom font, it will be transmitted over the network (more than one custom font cannot be transmitted per 1 tick)
- display.getFont():font - returns the value set using setFont (default by nil)
- display.getFontWidth():number - returns the width of a character using scaleX
- display.getFontHeight():number - returns the height of a character using scaleY
- display.getFontSize():number, number - returns the width and height of a character using scaleX and scaleY
- display.getRealFontWidth():number - returns the width of a character without considering scaleX
- display.getRealFontHeight():number - returns the height of a character without considering scaleY
- display.getRealFontSize():number, number - returns the width and height of a character without considering scale
- display.setSkipAtNotSight(state:boolean) - if set to true, the display will not be updated for those players who are not looking at it (which in some cases increases FPS and reduces network load) (default: false)
- display.getSkipAtNotSight():boolean - returns the value set using display.setSkipAtNotSight (default: false)
- display.isMonospacedFont():boolean - returns true if a monospaced font is set
- display.setLight(number) - sets the glow level of the display (min:0, max:255) (default: 255)
- display.getLight():number - returns the value set using display.setLight (default: 255)
- display.reset() - resets all display settings but does not clear it
- display.setClicksAllowed(state:boolean) - turns the touchscreen on/off (default: false)
- display.getClicksAllowed():boolean - returns the value set using display.setClicksAllowed (default: false)
- display.clearClicks() - clears the click buffer
- display.setMaxClicks(number) - sets the maximum number of clicks that fit into the buffer from 1 to 16 (default: 16)
- display.getMaxClicks():number - returns the value set using display.setMaxClicks (default: 16)
- display.getClick():table - reads a table with information about the click. if there was no click, it will return nil
- display.getTouchs():{click, click, ...} - returns all currently active clicks in the "pressed" and "drag" states
- display.getTouch():click - returns the first active click
--the structure of the click table
{
--string values
x = number, --the position of the click on X. from 0 to width
y = number, --the position of the click on Y. from 0 to height
state = string, --"pressed" / "released" / "drag"
button = number, --1 - left mouse button, 2 - right mouse button
nickname = string --player nickname
--number values
1 = number, --the position of the click on X. from 0 to width
2 = number, --the position of the click on Y. from 0 to height
3 = string, --"pressed" / "released" / "drag"
4 = number, --1 - left mouse button, 2 - right mouse button
5 = string --player nickname
}
display.clear(color) - fills the display with the specified color. resets the viewport even before clearing
display.setViewport(x:number, y:number, width:number, height:number) - sets the zone in which the rendering will take place, call without arguments to reset. note that flush resets the viewport
display.setInlineViewport(x:number, y:number, width:number, height:number) - sets the viewport as well as the setViewport. except that if the viewport is already installed, then this method will limit the new viewport to the boundaries of the old one (you get a kind of nested viewport without an overhead with checks)
display.getViewport():number, number, number, number - returns the currently installed viewport. or nothing if it is not installed
display.drawPixel(x, y, color) - sets 1 pixel on display
display.fillRect(x, y, sizeX, sizeY, color) - fills the rectangle
display.drawRect(x, y, sizeX, sizeY, color, lineWidth:number) - draws an empty rectangle. the line width is default 1. note that the line width increases "inside" the rectangle, that is, even if the line width of the rectangle is 10, the rectangle itself will still be exactly inscribed in its coordinates
display.drawText(x, y, text, color) - draws text of a given color at a given position
display.drawCenteredText(x, y, text, color, centerX:boolean (default: true), centerY:boolean (default: true)) - centers the text when rendering
display.drawLine(x, y, x2, y2, color, width:number, round:boolean) - draws a line on the displays from point A to point B. you can also set the line width. you can pass "round" to make the line rounded, but rasterizing such a line will be VERY SLOW. only makes sense at very high resolutions
display.drawCircle(x, y, radius, color) - draws an empty circle, please note that this circle cannot be exactly inscribed in a square and does not exactly fit on the display.fillCircle
display.drawCircleEvenly(x, y, radius, color) - a more accurate version of display.drawCircle. it can already be inscribed in a square (for example, drawn over the entire surface of the display) and lie more evenly on the display.fillCircle (however, it is not ideal)
display.drawCircleVeryEvenly(x, y, radius, color, stroke=1) - fits perfectly on display.fillCircle. can change the stroke size
display.fillCircle(x, y, radius, color) - fills a circle of a given radius at a given position
display.drawPoly(color, x, y, x, y, ...) - draws polygon without filling. pass the color and polygon points. then, in turn, x, y for each point
display.drawWidePoly(color, width:number, round:boolean, x, y, x, y, ...) - allows you to set the width of the line to be used and enable line rounding
display.fillPoly(color, x, y, x, y, ...) - fill polygon
display.fillWidePoly(color, width:number, round:boolean, x, y, x, y, ...) - fills the polygon, but allows you to adjust the width of the line and round it. in fact, it only makes sense if you want to round the polygon using a rounded line
display.drawTriangle(x1, y1, x2, y2, x3, y3, color) - draws a triangle
display.fillTriangle(x1, y1, x2, y2, x3, y3, color) - fills a triangle
display.drawEllipse(x, y, sizeX, sizeY, cornerRadius, color) - draws an ellipse within the specified square frame
display.fillEllipse(x, y, sizeX, sizeY, cornerRadius, color) - fills an ellipse within the specified square frame
display.flush() - sends the changes to the display. however, please note that your changes may be "lost" if the skipAtNotSight(this is disabled by default) flag is set and the player is not looking at the display. resets the viewport after sending
display.forceFlush() - sends the changes to the display. ensures that the image reaches the recipient. it ONLY makes sense if setSkipAtNotSight mode is enabled, but you still want to update the image for all users. doesn't make sense in others
display.setMaterial(material:number) - sets the display material
display.getMaterial():number - returns the current display material
display.getDefaultMaterial():number - returns the default material for this display
display.getDefaultResolution():x, y - gets the resolution of the display that is on it by default
display.setResolution(x:number, y:number) - changes the display resolution. on the world display or unrestricted display, you can set the resolution up to 4096x4096. On conventional displays, you can only set the resolution that meets two conditions: do not exceed the maximum number of pixels of the standard resolution, none of the resolution sides should exceed the maximum side of the standard resolution
only for holographic/world/unrestricted displays:
- display.setHoloOffset(x, y, z) - changes the displacement of the hologram relative to the display. the maximum offset is 5
- display.getHoloOffset():x, y, z - returns the value set using display.setOffset
- display.setHoloRotation(x, y, z, altRotation) - changes the rotation of the hologram relative to the display. when the alternative rotation mode is enabled, the rotation operation is performed first and only then the mixing operation is performed. Please note that the offset work slightly differently in this mode
- display.getHoloRotation():x, y, z, altRotation - returns the value set using display.setRotation
- display.setHoloScale(x, y) - sets the scale of the hologram. the maximum scale is 5
- display.getHoloScale():x, y - returns the value set using display.setScale
--ellipse example
local display = getComponent("display")
display.reset()
local rx, ry = display.getSize()
display.clear()
display.fillEllipse(16, 16, rx - 32, ry - 32, 15, 0xff0000)
display.drawEllipse(16, 16, rx - 32, ry - 32, 15, 0xff00ff)
display.flush()
function callback_loop()
if _endtick then
display.clear()
display.flush()
end
end
--example for display 256x256
--full fonts list: https://igorkll.github.io/fonts.html
local fonts = require("fonts")
local display = getComponent("display")
display.reset()
display.setTextSpacing(6) --in such large fonts, it would be more logical to spread the characters a little more than 1 pixel apart
display.setFontScale(1.8, 1.8) --is 32x32 small? you can make any font bigger!
display.clear()
local posY = 1
local text = "TEST"
display.setFont(fonts.impact_32)
local boxX, boxY = display.calcTextBox(text)
display.fillRect(1, posY, boxX, boxY, 0x00ff00)
display.drawText(1, posY, text, 0xff0000)
posY = posY + display.getFontHeight() + 3
display.setFont(fonts.verdana_32)
local boxX, boxY = display.calcTextBox(text)
display.fillRect(1, posY, boxX, boxY, 0x00ff00)
display.drawText(1, posY, text, 0xff0000)
posY = posY + display.getFontHeight() + 3
display.setFont(fonts.seguibl_32)
local boxX, boxY = display.calcTextBox(text)
display.fillRect(1, posY, boxX, boxY, 0x00ff00)
display.drawText(1, posY, text, 0xff0000)
posY = posY + display.getFontHeight() + 3
display.setFont(fonts.arial_32)
local boxX, boxY = display.calcTextBox(text)
display.fillRect(1, posY, boxX, boxY, 0x00ff00)
display.drawText(1, posY, text, 0xff0000)
posY = posY + display.getFontHeight() + 3
display.flush()
function callback_loop()
if _endtick then
display.clear()
display.flush()
return
end
end
local display = getComponents("display")[1]
display.reset()
display.clear()
display.setFont(
{
width = 3,
height = 3,
chars = {
error = {
"111",
"1.1",
"111"
},
a = {
".1.",
"111",
"1.1"
},
b = {
"1..",
"111",
"111"
},
c = {
"111",
"1..",
"111"
}
}
}
)
display.setFontSize(6, 12)
local boxX, boxY = display.calcTextBox("abcdef")
display.fillRect(1, 1, boxX, boxY, 0x00ff00)
display.drawText(1, 1, "abcdef", "ff0000")
display.flush()
function callback_loop()
if _endtick then
display.clear()
display.forceFlush()
end
end