love.graphics (简体中文)

(译者注:love.graphics 是 LÖVE 的核心组件,是一切绘制的基础。但是如你所见,这个页面已经很久没有更新了。如果可能,不妨尝试翻译一下这个页面吧!)

love.graphics 模块的主要功能是绘制(线段、图形、文字、图片 ImageDrawable 类型)到屏幕上。其次要功能是将外部文件(包括图片 Image、字体 Font)加载到内存中,建立专门的对象管理在屏幕上绘制的几何图形(例如粒子系统 ParticleSystemFramebuffer)。

LÖVE 的坐标系统如下图所示,以左上角为原点((0,0)),横向延伸为 x 轴,纵向延伸为 y 轴。

The LÖVE coordinate system

通常,绘制的图片和图形都是以它们的左上角为起点。(如上图)

坐标系统是图像在屏幕的某一位置显示的基础。有许多函数可以操作坐标系统。通过操作坐标,可以改变位置、大小、甚至旋转。

Types

CanvasOff-screen render target.
DrawableSuperclass for all things that can be drawn on screen.
FontDefines the shape of characters than can be drawn onto the screen.
FramebufferOff-screen render target.
ImageDrawable image type.
MeshA 2D polygon mesh used for drawing arbitrary textured shapes.
ParticleSystemUsed to create cool effects, like fire.
PixelEffectPixel shader effect.
QuadA quadrilateral with texture coordinate information.
ShaderShader effect.
SpriteBatchStore image positions in a buffer, and draw it in one call.
TextDrawable text.
TextureSuperclass for drawable objects which represent a texture.
VideoA drawable video.

Functions

Drawing

love.graphics.arc (简体中文) Draws an arc.绘制一段弧. Added since 0.8.0
love.graphics.checkMode (简体中文) Checks if a display mode is supported.检查是否支持这种显示模式.
love.graphics.circle (简体中文) Draws a circle.
love.graphics.draw (简体中文) Draws objects on screen.在屏幕上绘制物件。
love.graphics.printf (简体中文) Draws text on screen. If no Font is set, one will be created and set (once) if needed.绘制格式化过的文本,可折行显示、对齐。

Object Creation

love.graphics.newCanvas 创建一个新的画布
love.graphics.newFont 加载一个新的字体
love.graphics.newFramebuffer 创建一个新的帧缓冲区
love.graphics.newImage 加载一个新的图像
love.graphics.newImageFont 通过加载一个特定格式的图像创建一个新的字体
love.graphics.newParticleSystem 创建一个新的粒子系统.好帅的哦!
love.graphics.newPixelEffect 创建一个新的像素效果
love.graphics.newQuad 创建一个新的批发小图~
love.graphics.newScreenshot 创建一个截图并返回数据
love.graphics.newSpriteBatch 创建一个新的精灵图像组
love.graphics.newStencil 创建一个新的模板
love.graphics.setNewFont 创建并设置一个新的字体

Graphics State

love.graphics.getBackgroundColor Gets the current background color.
love.graphics.getBlendMode Gets the blending mode. Added since 0.2.0
love.graphics.getCanvas Returns the current target Canvas. Added since 0.8.0
love.graphics.getColor Gets the current color.
love.graphics.getColorMask Gets the active color components used when drawing. Added since 0.9.0
love.graphics.getColorMode Gets the color mode (which controls how images are affected by the current color). Added since 0.2.0 Removed in 0.9.0
love.graphics.getDefaultFilter Returns the default scaling filters used with Images, Canvases, and Fonts. Added since 0.9.0
love.graphics.getDefaultImageFilter Returns the default scaling filters. Added since 0.8.0 Removed in 0.9.0
love.graphics.getDepthMode Gets the current depth test mode and whether writing to the depth buffer is enabled. Added since 11.0
love.graphics.getFont Gets the current Font object. Added since 0.9.0
love.graphics.getFrontFaceWinding Gets whether triangles with clockwise- or counterclockwise-ordered vertices are considered front-facing. Added since 11.0
love.graphics.getLineJoin Gets the line join style.
love.graphics.getLineStipple Gets the current line stipple. Removed in 0.8.0
love.graphics.getLineStyle Gets the line style. Added since 0.3.2
love.graphics.getLineWidth Gets the current line width. Added since 0.3.2
love.graphics.getMeshCullMode Gets whether back-facing triangles in a Mesh are culled. Added since 11.0
love.graphics.getPixelEffect Returns the current PixelEffect. Added since 0.8.0 Removed in 0.9.0
love.graphics.getPointSize Gets the point size.
love.graphics.getPointStyle Gets the current point style. Removed in 0.10.0
love.graphics.getScissor Gets the current scissor box. Added since 0.4.0
love.graphics.getShader Gets the current Shader. Added since 0.9.0
love.graphics.getStackDepth Gets the current depth of the transform / state stack (the number of pushes without corresponding pops). Added since 11.0
love.graphics.getStencilTest Gets the current stencil test configuration. Added since 0.10.0
love.graphics.intersectScissor Sets the scissor to the rectangle created by the intersection of the specified rectangle with the existing scissor. Added since 0.10.0
love.graphics.isActive Gets whether the graphics module is able to be used. Added since 0.10.0
love.graphics.isGammaCorrect Gets whether gamma-correct rendering is enabled. Added since 0.10.0
love.graphics.isSupported Checks for the support of graphics related functions. Added since 0.8.0 Removed in 0.10.0
love.graphics.isWireframe Gets whether wireframe mode is used when drawing. Added since 0.9.1
love.graphics.reset Resets the current graphics settings.
love.graphics.setBackgroundColor Sets the background color.
love.graphics.setBlendMode Sets the blending mode. Added since 0.2.0
love.graphics.setCanvas Captures drawing operations to a Canvas Added since 0.8.0
love.graphics.setColor Sets the color used for drawing.
love.graphics.setColorMask Sets the color mask. Enables or disables specific color components when rendering. Added since 0.9.0
love.graphics.setColorMode Sets the color mode (which controls how images are affected by the current color). Added since 0.2.0 Removed in 0.9.0
love.graphics.setDefaultFilter Sets the default scaling filters used with Images, Canvases, and Fonts. Added since 0.9.0
love.graphics.setDefaultImageFilter Sets the default scaling filters. Added since 0.8.0 Removed in 0.9.0
love.graphics.setDepthMode Configures depth testing and writing to the depth buffer. Added since 11.0
love.graphics.setFont Set an already-loaded Font as the current font.
love.graphics.setFrontFaceWinding Sets whether triangles with clockwise- or counterclockwise-ordered vertices are considered front-facing. Added since 11.0
love.graphics.setInvertedStencil Defines an inverted stencil. Added since 0.8.0 Removed in 0.10.0
love.graphics.setLine Sets the line width and style. Removed in 0.9.0
love.graphics.setLineJoin Sets the line join style.
love.graphics.setLineStipple Sets the line stipple pattern. Removed in 0.8.0
love.graphics.setLineStyle Sets the line style. Added since 0.3.2
love.graphics.setLineWidth Sets the line width. Added since 0.3.2
love.graphics.setMeshCullMode Sets whether back-facing triangles in a Mesh are culled. Added since 11.0
love.graphics.setPixelEffect Routes drawing operations through a pixel shader. Added since 0.8.0 Removed in 0.9.0
love.graphics.setPoint Sets the point size and style. Removed in 0.9.0
love.graphics.setPointSize Sets the point size.
love.graphics.setPointStyle Sets the point style. Removed in 0.10.0
love.graphics.setRenderTarget Captures drawing operations to a Framebuffer Added since 0.7.0 Removed in 0.8.0
love.graphics.setScissor Sets or disables scissor. Added since 0.4.0
love.graphics.setShader Routes drawing operations through a shader. Added since 0.9.0
love.graphics.setStencil Defines or releases a stencil. Added since 0.8.0 Removed in 0.10.0
love.graphics.setStencilTest Configures or disables stencil testing. Added since 0.10.0
love.graphics.setWireframe Sets whether wireframe lines will be used when drawing. Added since 0.9.1

Coordinate System(坐标系统)

love.graphics.applyTransform Applies the given Transform object to the current coordinate transformation. Added since 11.0
love.graphics.inverseTransformPoint Converts the given 2D position from screen-space into global coordinates. Added since 11.0
love.graphics.origin Resets the current coordinate transformation. Added since 0.9.0
love.graphics.pop Pops the current coordinate transformation from the transformation stack.
love.graphics.push Copies and pushes the current coordinate transformation to the transformation stack.
love.graphics.replaceTransform Replaces the current coordinate transformation with the given Transform object. Added since 11.0
love.graphics.rotate Rotates the coordinate system in two dimensions.
love.graphics.scale Scales the coordinate system in two dimensions.
love.graphics.shear Shears the coordinate system. Added since 0.8.0
love.graphics.transformPoint Converts the given 2D position from global coordinates into screen-space. Added since 11.0
love.graphics.translate Translates the coordinate system in two dimensions.

Window

love.graphics.checkMode Checks if a display mode is supported. Removed in 0.9.0
love.graphics.getCaption Gets the window caption. Removed in 0.9.0
love.graphics.getDPIScale Gets the DPI scale factor of the window. Added since 11.0
love.graphics.getDimensions Gets the width and height of the window. Added since 0.9.0
love.graphics.getHeight Gets the height in pixels of the window. Added since 0.2.1
love.graphics.getMode Returns the current display mode. Added since 0.8.0 Removed in 0.9.0
love.graphics.getModes Gets a list of supported fullscreen modes. Removed in 0.9.0
love.graphics.getPixelDimensions Gets the width and height in pixels of the window. Added since 11.0
love.graphics.getPixelHeight Gets the height in pixels of the window. Added since 11.0
love.graphics.getPixelWidth Gets the width in pixels of the window. Added since 11.0
love.graphics.getWidth Gets the width in pixels of the window. Added since 0.2.1
love.graphics.hasFocus Checks if the game window has keyboard focus. Added since 0.8.0 Removed in 0.9.0
love.graphics.isCreated Checks if the window has been created. Removed in 0.9.0
love.graphics.setCaption Sets the window caption. Removed in 0.9.0
love.graphics.setIcon Set window icon. Added since 0.7.0 Removed in 0.9.0
love.graphics.setMode Changes the display mode. Removed in 0.9.0
love.graphics.toggleFullscreen Toggles fullscreen. Removed in 0.9.0

Enums

AlignMode Text alignment.
ArcType Different types of arcs that can be drawn. Added since 0.10.1
AttributeDataType Data types used in a Mesh's vertex format. Added since 0.9.0
BlendAlphaMode Different ways alpha affects color blending. Added since 0.10.0
BlendMode Different ways to do color blending. Added since 0.2.0
CanvasFormat Canvas texture formats. Added since 0.9.0
ColorMode Controls how drawn images are affected by current color. Added since 0.2.0 Removed in 0.9.0
CompareMode Different types of stencil test and depth test comparisons. Added since 0.10.0
CullMode How Mesh geometry is culled when rendering. Added since 11.0
DrawMode Controls whether shapes are drawn as an outline, or filled.
FilterMode How the image is filtered when scaling.
GraphicsFeature Graphics features that can be checked for with love.graphics.getSupported. Added since 0.8.0
GraphicsLimit Types of system-dependent graphics limits. Added since 0.9.1
IndexDataType Vertex map datatype. Added since 11.0
LineJoin Line join style.
LineStyle The styles in which lines are drawn.
MeshDrawMode How a Mesh's vertices are used when drawing. Added since 0.9.0
MipmapMode Controls whether a Canvas has mipmaps, and its behaviour when it does. Added since 11.0
PixelFormat Pixel formats for Textures, ImageData, and CompressedImageData. Added since 11.0
PointStyle How points should be drawn. Removed in 0.10.0
SpriteBatchUsage Usage hints for SpriteBatches and Meshes. Added since 0.8.0
StackType Graphics state stack types used with love.graphics.push. Added since 0.9.2
StencilAction How a stencil function modifies the stencil values of pixels it touches. Added since 0.10.0
TextureFormat Controls the canvas texture format. Added since 0.9.0 Removed in 0.10.0
TextureType Types of textures (2D, cubemap, etc.) Added since 11.0
VertexAttributeStep The frequency at which a vertex shader fetches the vertex attribute's data from the Mesh when it's drawn. Added since 11.0
VertexWinding Vertex winding. Added since 11.0
WrapMode How the image wraps inside a large Quad.

See Also

Other Languages