### LOVE Physics Module: Common Workflow Example Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Demonstrates the basic setup and usage of the LOVE Physics Module, including creating a physics world, static ground, dynamic player, and handling input, updates, and drawing. ```lua function love.load() -- Create world world = love.physics.newWorld(0, 9.81) -- Create ground (static body) groundBody = love.physics.newBody(world, 400, 550, 'static') groundShape = love.physics.newEdgeShape(0, 0, 800, 0) groundFixture = groundBody:addShape(groundShape) groundFixture:setFriction(0.4) -- Create player (dynamic body) playerBody = love.physics.newBody(world, 400, 100, 'dynamic') playerShape = love.physics.newCircleShape(20) playerFixture = playerBody:addShape(playerShape) playerFixture:setDensity(1.0) playerFixture:setFriction(0.3) playerFixture:setRestitution(0.5) end function love.update(dt) -- Step the simulation world:update(dt) -- Apply player input if love.keyboard.isDown('left') then playerBody:applyForce(-100, 0) end if love.keyboard.isDown('right') then playerBody:applyForce(100, 0) end end function love.draw() local meter = love.physics.getMeter() -- Draw player local px, py = playerBody:getPosition() love.graphics.circle('fill', px * meter, py * meter, 20) -- Draw ground local gx, gy = groundBody:getPosition() love.graphics.line(gx * meter, gy * meter, (gx + 800) * meter, gy * meter) end ``` -------------------------------- ### Complete love.conf Example Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md This snippet shows a comprehensive example of the love.conf function, covering various settings for game identity, version, window properties, audio, and module enabling/disabling. ```lua function love.conf(t) t.identity = "my_game" t.appendidentity = false t.version = "11.5" t.console = false t.accelerometerjoystick = true t.externalstorage = false t.gammacorrect = false t.audio.mic = false t.audio.mixwithsystem = true t.window.title = "Epic Adventure" t.window.width = 1280 t.window.height = 720 t.window.resizable = false t.window.vsync = 1 t.window.display = 1 t.modules.audio = true t.modules.event = true t.modules.graphics = true t.modules.image = true t.modules.joystick = true t.modules.keyboard = true t.modules.math = true t.modules.mouse = true t.modules.physics = true t.modules.sound = true t.modules.system = true t.modules.timer = true t.modules.touch = false -- Not a mobile game t.modules.video = false -- No video playback needed t.modules.window = true t.modules.thread = false -- Single-threaded end ``` -------------------------------- ### Complete Game Loop Example Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md A full example demonstrating the game loop with love.conf, love.load, love.update, love.draw, love.keypressed, love.mousepressed, and love.quit callbacks. ```lua function love.conf(t) t.window.width = 800 t.window.height = 600 t.window.title = "Game Loop Example" end local player = {} local enemies = {} function love.load() player = {x = 400, y = 300, speed = 200, image = love.graphics.newImage("player.png")} love.graphics.setBackgroundColor(0.2, 0.2, 0.2) end function love.update(dt) -- Player movement if love.keyboard.isDown('left') then player.x = player.x - player.speed * dt end if love.keyboard.isDown('right') then player.x = player.x + player.speed * dt end end function love.draw() love.graphics.clear() love.graphics.setColor(1, 1, 1) love.graphics.draw(player.image, player.x, player.y) love.graphics.print("Position: " .. math.floor(player.x) .. ", " .. math.floor(player.y), 10, 10) end function love.keypressed(key) if key == "escape" then love.event.quit() end end function love.mousepressed(x, y, button) if button == 1 then player.x = x player.y = y end end function love.quit() print("Thanks for playing!") end ``` -------------------------------- ### Setting Colors (Gray Example) Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md Example of setting a gray color using normalized 0-1 values. ```lua love.graphics.setColor(0.5, 0.5, 0.5) -- Gray ``` -------------------------------- ### Full Example: Moving Square in LÖVE Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md A complete LÖVE game example demonstrating window configuration, player movement with keyboard input, drawing a rectangle, and handling escape to quit. ```lua function love.conf(t) t.window.width = 800 t.window.height = 600 t.window.title = "Moving Square" end local player = {x = 400, y = 300, speed = 200, size = 30} function love.update(dt) if love.keyboard.isDown('up') or love.keyboard.isDown('w') then player.y = player.y - player.speed * dt end if love.keyboard.isDown('down') or love.keyboard.isDown('s') then player.y = player.y + player.speed * dt end if love.keyboard.isDown('left') or love.keyboard.isDown('a') then player.x = player.x - player.speed * dt end if love.keyboard.isDown('right') or love.keyboard.isDown('d') then player.x = player.x + player.speed * dt end end function love.draw() love.graphics.clear(0.1, 0.1, 0.1) love.graphics.setColor(1, 0, 0) love.graphics.rectangle('fill', player.x - player.size / 2, player.y - player.size / 2, player.size, player.size) love.graphics.setColor(1, 1, 1) love.graphics.print("Use arrow keys to move", 10, 10) end function love.keypressed(key) if key == "escape" then love.event.quit() end end ``` -------------------------------- ### Start Audio Recording Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Begins recording audio input from the default or selected device. ```lua function love.audio.startRecording(): boolean ``` -------------------------------- ### Get Recording Devices and Initialize Source Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves available audio input devices and initializes a new audio source from the first available device. Requires 't.audio.mic = true' in love.conf. ```lua function love.load() devices = love.audio.getRecordingDevices() if #devices > 0 then device = devices[1] recorder = love.audio.newSource( love.audio.getRecordingDevices()[1], 'queue' ) end end ``` -------------------------------- ### Initialize Game Resources Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/04-modules-overview.md Use the love.load function to create graphics, audio, physics, and input resources when the game starts. Ensure all necessary files exist. ```lua function love.load() -- Create graphics resources image = love.graphics.newImage("player.png") font = love.graphics.newFont(24) canvas = love.graphics.newCanvas(800, 600) -- Create audio resources sound = love.audio.newSource("jump.wav", "static") music = love.audio.newSource("theme.ogg", "stream") -- Create physics world world = love.physics.newWorld(0, 9.81) -- Create input devices joysticks = love.joystick.getJoysticks() end ``` -------------------------------- ### Basic Configuration Callback Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Sets window dimensions and disables the physics module. This is a fundamental example of the love.conf structure. ```lua function love.conf(t) t.window.width = 1024 t.window.height = 768 t.modules.physics = false end ``` -------------------------------- ### LOVE API Documentation Learning Path Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/DELIVERY.md Illustrates the recommended sequence for learning the LOVE API, starting with an overview and progressing to specific modules and detailed references. ```markdown README.md ← Start here: what is this? ↓ QUICK-START.md ← Beginner: essentials in 5 minutes ↓ INDEX.md ← Navigator: find anything ↓ Specific modules ← Deep dives into each API ↓ TYPE/CALLBACK refs ← Complete reference ``` -------------------------------- ### LÖVE Input Handling Examples Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/INDEX.md Shows how to detect keyboard key presses, handle mouse clicks with coordinates and button type, and respond to gamepad button events. ```lua -- Keyboard if love.keyboard.isDown('w') then playerMove() end -- Mouse function love.mousepressed(x, y, button) if button == 1 then onClick(x, y) end end -- Gamepad function love.gamepadpressed(joystick, button) if button == 'a' then playerJump() end end ``` -------------------------------- ### love.filesystem.getSize Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Gets the size of a file in bytes. ```APIDOC ## love.filesystem.getSize ### Description Gets the size of a file in bytes. ### Signature ```lua function love.filesystem.getSize(filename: string): number ``` ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the file. ### Return Values - **number** - The size of the file in bytes. ``` -------------------------------- ### Configure LÖVE Window and Modules Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md Use the love.conf callback to set window dimensions, title, and enable/disable specific LÖVE modules before the game starts. ```lua function love.conf(t) t.window.width = 1024 t.window.height = 768 t.window.title = "My Game" t.modules.physics = false t.modules.video = false end ``` -------------------------------- ### love.audio.play Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Starts or resumes playback of an audio source. ```APIDOC ## love.audio.play ### Description Plays the specified audio source. If the source is already playing, this function may restart it or have no effect depending on the source type and current state. ### Signature ```lua function love.audio.play(source: Source): nil ``` ### Parameters #### Path Parameters - **source** (Source) - Required - The audio source to play. ### Example ```lua -- Play a sound when the space key is pressed function love.keypressed(key) if key == "space" then love.audio.play(jumpSound) end end ``` ``` -------------------------------- ### Play Audio Source Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Starts or resumes playback of an audio source. ```lua source:play() ``` -------------------------------- ### Open and Read/Write Files Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Demonstrates opening a file in read mode to get its content and then opening it again in write mode to overwrite it. Ensure files are closed after use. ```lua function love.load() -- Read file local file = love.filesystem.newFile("data.txt", "r") local content = file:read() file:close() -- Write file local file = love.filesystem.newFile("data.txt", "w") file:write("Hello, World!") file:close() end ``` -------------------------------- ### love.filesystem.getWorkingDirectory Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Gets the working directory (game directory). This is the directory from which the game was launched. ```APIDOC ## love.filesystem.getWorkingDirectory ### Description Gets the working directory (game directory). ### Method GET ### Endpoint /love.filesystem.getWorkingDirectory ### Return Values - **path** (string) - The full path to the game's working directory. ``` -------------------------------- ### IDE Suggests Parameters Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/01-api-structure.md An IDE uses the API structure to suggest parameters for functions. This example shows how a function signature is displayed on hover. ```lua -- IDE uses this structure to suggest parameters: love.graphics.draw(drawable, ...) ^ [Function signature from function table] ``` -------------------------------- ### LÖVE File I/O Operations Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/INDEX.md Provides examples for reading data from a file, writing content to a file, checking if a file exists, and listing items within a directory. ```lua -- Read file data = love.filesystem.read("config.txt") -- Write file love.filesystem.write("savegame.txt", content) -- Check existence if love.filesystem.exists("file.txt") then ... end -- List directory local items = love.filesystem.getDirectoryItems("") ``` -------------------------------- ### source:play Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Starts or resumes playback of the audio source. ```APIDOC ## source:play ### Description Plays the source. If the source is paused, it will resume. If it is stopped, it will start from the beginning. ### Method `play()` ### Endpoint N/A (SDK Method) ### Parameters None ### Response None ``` -------------------------------- ### Example Function Signature Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/INDEX.md Illustrates the format for function signatures, including return types and parameter types. This format is used throughout the documentation. ```lua function love.graphics.circle(mode: DrawMode, x: number, y: number, radius: number): nil ``` -------------------------------- ### Handle Text Input Field Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md This example demonstrates how to build a text input field using the textinput and keypressed callbacks. It handles character input, backspace, and return submission. ```lua local inputText = "" function love.textinput(text) inputText = inputText .. text end function love.keypressed(key) if key == "backspace" then inputText = inputText:sub(1, -2) elseif key == "return" then submitInput(inputText) inputText = "" end end function love.draw() love.graphics.print("Enter name: " .. inputText, 10, 10) end ``` -------------------------------- ### Table Argument Structure Example Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/01-api-structure.md Illustrates the structure for a table argument or return value, detailing its type, name, description, and nested fields. ```lua { type = 'table', name = 'config', description = 'Configuration options', table = { { type = 'string', name = 'title', description = 'Window title', default = '"Untitled"' }, { type = 'number', name = 'width', description = 'Window width in pixels', default = '800' } } } ``` -------------------------------- ### Handle Mouse Movement for Camera Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md This example shows how to implement a free-look camera using the mousemoved callback. It updates camera position based on mouse delta when the right mouse button is held down. ```lua local cameraX, cameraY = 0, 0 function love.mousemoved(x, y, dx, dy) if rightMouseDown then cameraX = cameraX - dx cameraY = cameraY - dy end end ``` -------------------------------- ### Callback Structure Example Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/01-api-structure.md Defines the structure for a callback in the root `callbacks` array, including its name, description, and variants. ```lua { name = 'draw', description = 'Callback function used to draw on screen every frame.', variants = { { -- No arguments, no returns } } } ``` -------------------------------- ### Generate Function Synopsis List Source: https://github.com/love2d-community/love-api/blob/master/README.md This example demonstrates how to iterate through API variants, sort them by function name, and generate a formatted string listing function return values, names, arguments, and default values. It requires the extra module to be initialized. ```lua api = require('extra')(require('love-api.love_api')) table.sort(api.variants, function(a, b) return a.function_.fullname < b.function_.fullname end) local s = '' for _, variant in ipairs(api.variants) do local function list(t) local s = '' for i, a in ipairs(t) do s = s..a.name if a.default then s = s..' ['..a.default..']' end if i ~= #t then s = s..', ' end end return s end if #variant.returns > 0 then s = s..list(variant.returns)..' = ' end s = s..variant.function_.fullname..'(' if #variant.arguments > 0 then s = s..list(variant.arguments) end s = s..')\n' end print(s) ``` -------------------------------- ### Create and Play Audio Stream Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Creates a new audio source from a file, sets it to loop, adjusts its volume, and starts playback. Use for background music or ambient sounds. ```lua function love.load() backgroundMusic = love.audio.newSource("theme.ogg", "stream") backgroundMusic:setLooping(true) backgroundMusic:setVolume(0.5) love.audio.play(backgroundMusic) end ``` -------------------------------- ### Set Window Display Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Specifies which display to show the window on in a multi-monitor setup. Displays are 1-indexed. Query available displays with `love.window.getDisplayCount()`. ```lua function love.conf(t) t.window.display = 2 -- Show on second monitor (1-indexed) end ``` -------------------------------- ### Get Audio Source Duration Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Gets the total playback duration of the audio source, either in seconds or samples. ```lua duration = source:getDuration() source:getDuration('samples') ``` -------------------------------- ### Get Audio Source Playback Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Gets the current playback position of the audio source, either in seconds or samples. ```lua time = source:getTell() source:getTell('samples') ``` -------------------------------- ### Apply Transform to Drawing Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Demonstrates how to create, modify, and apply a transform to alter the drawing context. This example translates and rotates the coordinate system before drawing a rectangle. ```lua function love.draw() local transform = love.math.newTransform() transform:translate(400, 300) transform:rotate(math.pi / 4) love.graphics.applyTransform(transform) love.graphics.rectangle('fill', -50, -50, 100, 100) end ``` -------------------------------- ### Handle Text Input for Chat Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/08-keyboard-mouse-input.md This example demonstrates how to capture typed text for a chat input field. It uses the love.textinput callback to append characters and love.keypressed to handle backspace. ```lua local inputText = "" function love.textinput(text) inputText = inputText .. text end function love.keypressed(key) if key == "backspace" then inputText = inputText:sub(1, -2) end end function love.draw() love.graphics.print("Input: " .. inputText, 10, 10) end ``` -------------------------------- ### Get Mouse Position and Draw Circle Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/08-keyboard-mouse-input.md Demonstrates how to get the current mouse coordinates and use them to draw a circle at that position in the draw function. ```lua function love.draw() local x, y = love.mouse.getPosition() love.graphics.circle('fill', x, y, 5) end ``` -------------------------------- ### Prevent Application Exit Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md This example shows how to use the love.quit callback to perform cleanup operations like saving game state before the application exits. Returning false allows the exit. ```lua function love.quit() -- Save game state saveGame() -- Close databases, files, etc. closeConnections() -- Allow exit return false end ``` -------------------------------- ### LÖVE Physics Simulation Workflow Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/INDEX.md Illustrates setting up a physics world, creating dynamic bodies, adding collision shapes, stepping the simulation, and retrieving body positions. ```lua -- Create world world = love.physics.newWorld(0, 9.81) -- Create body body = love.physics.newBody(world, x, y, 'dynamic') -- Add collision shape shape = love.physics.newCircleShape(radius) fixture = body:addShape(shape) -- Step simulation world:update(dt) -- Read results x, y = body:getPosition() ``` -------------------------------- ### Allow Background Audio Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Allows background music and audio from other apps to continue playing while LÖVE is running. Set to `false` to pause music when the game starts. ```lua function love.conf(t) t.audio.mixwithsystem = false -- Music pauses when game starts end ``` -------------------------------- ### Basic LÖVE Configuration Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md Configure window dimensions, title, and disable unused modules for faster startup. Set the game's identity for save directory. ```lua function love.conf(t) -- Window t.window.width = 1024 t.window.height = 768 t.window.title = "My Game" -- Save directory t.identity = "my_game" -- Disable unused modules (faster startup) t.modules.physics = false t.modules.video = false -- Audio settings t.audio.mic = false t.audio.mixwithsystem = true end ``` -------------------------------- ### File:tell Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Gets the current position in the file. ```APIDOC ## File:tell ### Description Returns the current position within the file. ### Method `file:tell()` ### Response * `position` (number) - The current position in the file. ``` -------------------------------- ### Fixture:getBody Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Gets the body to which the fixture is attached. ```APIDOC ## Fixture:getBody ### Description Gets the body to which the fixture is attached. ### Method GET ### Endpoint `/fixture/body` ### Response #### Success Response (200) - **body** (object) - The body object associated with the fixture. ### Response Example ```json { "body": { "id": "body123" } } ``` ``` -------------------------------- ### Reading and Writing Files with Filesystem Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Demonstrates reading a file relative to the configured identity path and writing to a subdirectory. Ensure directories are created before writing. ```lua -- This reads from: ~/.local/share/love/mygame/data.txt local data = love.filesystem.read("data.txt") -- This creates: ~/.local/share/love/mygame/saves/game1.txt love.filesystem.createDirectory("saves") love.filesystem.write("saves/game1.txt", "...") ``` -------------------------------- ### Body:getMass Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Gets the mass of the physics body. ```APIDOC ## Body:getMass ### Description Gets the mass of the physics body. ### Method GET ### Endpoint `/body/mass` ### Response #### Success Response (200) - **mass** (number) - The mass of the body. ### Response Example ```json { "mass": 10 } ``` ``` -------------------------------- ### Configuration File Handling Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Loads and saves application configuration from a plain text file. Parses key-value pairs. ```lua local config = { volume = 0.8, fullscreen = false, difficulty = "normal" } function loadConfig() if love.filesystem.exists("config.txt") then local content = love.filesystem.read("config.txt") for line in content:gmatch("[^ ]+") do local key, value = line:match("(.+)=(.+)") if key then config[key] = value end end end end function saveConfig() local lines = {} for key, value in pairs(config) do table.insert(lines, key .. "=" .. tostring(value)) end love.filesystem.write("config.txt", table.concat(lines, "\n")) end ``` -------------------------------- ### File:getSize Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Gets the total size of the file in bytes. ```APIDOC ## File:getSize ### Description Returns the total size of the file in bytes. ### Method `file:getSize()` ### Response * `size` (number) - The size of the file in bytes. ``` -------------------------------- ### Get File Size Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Retrieves the size of a file in bytes. ```lua function love.filesystem.getSize(filename: string): number ``` -------------------------------- ### Implement Camera Panning with Right-Click Drag Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/08-keyboard-mouse-input.md In the mousemoved callback, this example implements camera panning functionality. If the right mouse button is held down, the camera position (cameraX, cameraY) is adjusted based on the mouse's change in position (dx, dy). ```lua local cameraX, cameraY = 0, 0 function love.mousemoved(x, y, dx, dy) if love.mouse.isDown(2) then -- Right-click drag cameraX = cameraX - dx cameraY = cameraY - dy end end ``` -------------------------------- ### Body:getPosition Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Gets the current position of the physics body. ```APIDOC ## Body:getPosition ### Description Gets the current position of the physics body. ### Method GET ### Endpoint `/body/position` ### Response #### Success Response (200) - **x** (number) - The x-coordinate of the body's position. - **y** (number) - The y-coordinate of the body's position. ### Response Example ```json { "x": 100, "y": 200 } ``` ``` -------------------------------- ### Set up Physics World and Bodies Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md Initialize the physics world with gravity and create dynamic bodies with shapes. Apply forces to bodies in the update loop. ```lua function love.load() world = love.physics.newWorld(0, 9.81) -- Gravity -- Create a dynamic body playerBody = love.physics.newBody(world, 400, 100, 'dynamic') playerShape = love.physics.newCircleShape(20) playerBody:addShape(playerShape) end function love.update(dt) world:update(dt) -- Step physics if love.keyboard.isDown('space') then playerBody:applyForce(0, -500) -- Jump end end function love.draw() local x, y = playerBody:getPosition() love.graphics.circle('fill', x, y, 20) end ``` -------------------------------- ### love.audio.startRecording Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Begins the process of recording audio input from the selected device. ```APIDOC ## love.audio.startRecording ### Description Begins recording audio input. ### Signature ```lua function love.audio.startRecording(): boolean ``` ``` -------------------------------- ### Get Fixture Body Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Retrieves the body to which a fixture is attached. ```lua body = fixture:getBody() ``` -------------------------------- ### Get Body Mass Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Retrieves the mass of a physics body. ```lua mass = body:getMass() ``` -------------------------------- ### love.conf Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md The configuration callback, which runs before module initialization to set up game window, modules, and other settings. ```APIDOC ## love.conf ### Description Configuration callback; runs before module initialization. ### Signature ```lua function love.conf(t) -- Modify configuration table end ``` ### Parameters #### Path Parameters - **t** (table) - Required - Configuration table with all default values ### When Called - Before any modules are loaded - Once per game launch ### Purpose Configure LÖVE behavior: window size, module enablement, audio settings, etc. ### Example ```lua function love.conf(t) t.window.width = 1024 t.window.height = 768 t.window.title = "My Game" t.modules.physics = false t.modules.video = false end ``` ### See Also - [Configuration Reference](./03-configuration.md) ``` -------------------------------- ### Create Directory Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Creates a new directory at the specified path. Returns true on success, false otherwise. ```lua function love.load() if not love.filesystem.exists("saves") then love.filesystem.createDirectory("saves") end end ``` -------------------------------- ### Get File Size Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Returns the total size of the file in bytes. ```lua size = file:getSize() ``` -------------------------------- ### Initialize Game State and Resources Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md The love.load callback is used for one-time initialization tasks such as loading assets, setting up player properties, and creating physics worlds. ```lua function love.load() player = { x = 400, y = 300, speed = 200 } playerImage = love.graphics.newImage("player.png") jumpSound = love.audio.newSource("jump.wav", "static") world = love.physics.newWorld(0, 9.81) end ``` -------------------------------- ### Get File Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Retrieves the current position within the file. ```lua position = file:tell() ``` -------------------------------- ### Create and Manage a Particle System Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/06-graphics-module.md Initializes a particle system with a texture, sets emission properties, and updates/draws particles. Requires a 'particle.png' image. ```lua function love.load() particleTexture = love.graphics.newImage("particle.png") particles = love.graphics.newParticleSystem(particleTexture) particles:setParticleLifetime(2) particles:setEmissionRate(100) end function love.update(dt) particles:update(dt) end function love.draw() love.graphics.draw(particles, 400, 300) end ``` -------------------------------- ### love.filesystem.getModificationTime Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Gets the last modification time of a file as a Unix timestamp. ```APIDOC ## love.filesystem.getModificationTime ### Description Gets the last modification time of a file as a Unix timestamp. ### Signature ```lua function love.filesystem.getModificationTime(filename: string): number ``` ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the file. ### Return Values - **number** - The last modification time as a Unix timestamp. ``` -------------------------------- ### Body:getLinearVelocity Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Gets the current linear velocity of the physics body. ```APIDOC ## Body:getLinearVelocity ### Description Gets the current linear velocity of the physics body. ### Method GET ### Endpoint `/body/velocity` ### Response #### Success Response (200) - **vx** (number) - The x-component of the body's linear velocity. - **vy** (number) - The y-component of the body's linear velocity. ### Response Example ```json { "vx": 10, "vy": 5 } ``` ``` -------------------------------- ### love.filesystem.createDirectory Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Creates a new directory at the specified path. ```APIDOC ## love.filesystem.createDirectory ### Description Creates a directory at the specified path. ### Signature ```lua function love.filesystem.createDirectory(name: string): boolean ``` ### Parameters #### Path Parameters - **name** (string) - Required - The path for the new directory to be created. ### Return Values - **boolean** - Returns true if the directory was created successfully, false otherwise. ### Example ```lua function love.load() if not love.filesystem.exists("saves") then love.filesystem.createDirectory("saves") end end ``` ``` -------------------------------- ### Get Audio Source Velocity Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current velocity of the audio source. ```lua vx, vy, vz = source:getVelocity() ``` -------------------------------- ### Get Master Volume Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current master volume setting for all audio. ```lua local currentVolume = love.audio.getVolume() ``` -------------------------------- ### Create Audio Sources Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Creates audio sources for playback. Use 'static' for short sounds and 'stream' for longer audio files. Static sounds are loaded entirely into memory, while streamed sounds are loaded as needed. ```lua function love.load() -- Short sound effect (loaded all at once) jumpSound = love.audio.newSource("jump.wav", "static") -- Long music track (streamed from disk) backgroundMusic = love.audio.newSource("theme.ogg", "stream") end ``` -------------------------------- ### LÖVE Graphics Rendering Workflow Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/INDEX.md Demonstrates loading resources like images and fonts, drawing basic shapes, and rendering text and images to the screen. ```lua -- Load resources image = love.graphics.newImage("file.png") font = love.graphics.newFont(24) canvas = love.graphics.newCanvas(800, 600) -- Draw shapes love.graphics.setColor(1, 0, 0) love.graphics.rectangle('fill', 100, 100, 200, 200) -- Draw images love.graphics.draw(image, 0, 0) -- Draw text love.graphics.print("Hello", font, 10, 10) ``` -------------------------------- ### Get Listener Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current listener's position in 3D space. ```lua function love.audio.getPosition(): (number, number, number) ``` -------------------------------- ### Initialize and Use a Particle System Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Initializes a particle system with a texture and configures its properties like lifetime, emission rate, and speed. Use update to advance particle states and draw to render them. ```lua function love.load() local texture = love.graphics.newImage("particle.png") particles = love.graphics.newParticleSystem(texture, 1000) particles:setParticleLifetime(2) particles:setEmissionRate(100) end function love.update(dt) particles:update(dt) end function love.draw() love.graphics.draw(particles, 400, 300) end ``` -------------------------------- ### Create and Draw a SpriteBatch Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Initialize a SpriteBatch with an image and pre-load it with multiple instances. Draw the entire batch efficiently in the draw function. ```lua function love.load() local tileImage = love.graphics.newImage("tile.png") tileBatch = love.graphics.newSpriteBatch(tileImage) -- Pre-load all tiles for x = 0, 9 do for y = 0, 9 do tileBatch:add(x * 32, y * 32) end end end function love.draw() love.graphics.draw(tileBatch, 0, 0) end ``` -------------------------------- ### Get Active Audio Effects Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves a list of currently enabled audio effects. ```lua function love.audio.getActiveEffects(): table ``` -------------------------------- ### Initialize Physics World and Update Simulation Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Create a new physics world with specified gravity. Call the world:update() method in love.update to step the simulation. ```lua function love.load() world = love.physics.newWorld(0, 9.81) end function love.update(dt) world:update(dt) end ``` -------------------------------- ### Get Audio Source Rolloff Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current rolloff setting for the audio source. ```lua rolloff = source:getRolloff() ``` -------------------------------- ### Get Audio Source Pitch Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current pitch setting of the audio source. ```lua pitch = source:getPitch() ``` -------------------------------- ### Load and Play Audio Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md Create audio sources for music and sound effects. Use 'stream' for long music files and 'static' for short sounds. Set looping for background music. ```lua function love.load() backgroundMusic = love.audio.newSource("theme.ogg", "stream") jumpSound = love.audio.newSource("jump.wav", "static") backgroundMusic:setLooping(true) love.audio.play(backgroundMusic) end function love.keypressed(key) if key == "space" then love.audio.play(jumpSound) end end ``` -------------------------------- ### Get Audio Source Volume Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current volume setting of the audio source. ```lua volume = source:getVolume() ``` -------------------------------- ### Get Audio Effect Settings Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the configuration settings for a specific audio effect by its name. ```lua function love.audio.getEffect(name: string): table ``` -------------------------------- ### Deferred Window Creation Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Defers window creation until `love.window.setMode()` is called in `love.load()`. Warning: Calling `love.graphics` functions before creating a window will crash. ```lua function love.conf(t) t.window = nil end function love.load() -- Window does not exist yet love.window.setMode(800, 600) -- Create now end ``` -------------------------------- ### source:getDuration Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Gets the total playback duration of the audio source, either in seconds or samples. ```APIDOC ## source:getDuration ### Description Retrieves the total playback duration of the audio source. The duration can be returned in seconds (default) or in audio samples. ### Method `getDuration([unit])` ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters - **unit** (string) - Optional - Specifies the unit for the returned duration. Accepts 'samples' for audio samples. Defaults to seconds if not provided. ``` -------------------------------- ### source:getTell Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Gets the current playback position of the audio source, either in seconds or samples. ```APIDOC ## source:getTell ### Description Retrieves the current playback position of the audio source. The position can be returned in seconds (default) or in audio samples. ### Method `getTell([unit])` ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters - **unit** (string) - Optional - Specifies the unit for the returned position. Accepts 'samples' for audio samples. Defaults to seconds if not provided. ``` -------------------------------- ### love.load Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/10-callbacks-reference.md The initialization callback, which runs once after modules load to set up the game state and load resources. ```APIDOC ## love.load ### Description Initialization callback; runs once after modules load. ### Signature ```lua function love.load() -- Initialize game state end ``` ### When Called - Once, after LÖVE modules initialize - Before any update or draw calls ### Purpose Load resources, initialize game state, set up objects. ### Example ```lua function love.load() player = { x = 400, y = 300, speed = 200 } playerImage = love.graphics.newImage("player.png") jumpSound = love.audio.newSource("jump.wav", "static") world = love.physics.newWorld(0, 9.81) end ``` ``` -------------------------------- ### Get Audio Source Direction Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current directional audio vector of the audio source. ```lua x, y, z = source:getDirection() ``` -------------------------------- ### Create and Manage a Table of Objects Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md Demonstrates creating a table to hold multiple game objects (enemies) and updating their positions based on their individual speeds and delta time. Objects are drawn as circles. ```lua local enemies = {} function spawnEnemy(x, y) table.insert(enemies, {x = x, y = y, speed = 100}) end function love.update(dt) for _, enemy in ipairs(enemies) do enemy.x = enemy.x + enemy.speed * dt end end function love.draw() for _, enemy in ipairs(enemies) do love.graphics.circle('fill', enemy.x, enemy.y, 10) end end ``` -------------------------------- ### Get File Modification Time Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Retrieves the last modification time of a file as a Unix timestamp. ```lua function love.filesystem.getModificationTime(filename: string): number ``` -------------------------------- ### Get Body Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Retrieves the current position of a physics body. Returns the x and y coordinates. ```lua x, y = body:getPosition() ``` -------------------------------- ### Require love-api.extra Source: https://github.com/love2d-community/love-api/blob/master/README.md This snippet shows how to require the extra module and initialize it with the main love_api. ```lua api = require('love-api.extra')(require('love-api.love_api')) ``` -------------------------------- ### Get Audio Source 3D Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the current 3D spatial position of the audio source. ```lua x, y, z = source:getPosition() ``` -------------------------------- ### Enable Microphone Access Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Requests microphone permission and enables recording. When granted, `love.audio.getRecordingDevices()` lists available devices. ```lua function love.conf(t) t.audio.mic = true end ``` -------------------------------- ### Hello World in LÖVE Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/QUICK-START.md The minimal code required to run a LÖVE application, displaying 'Hello, LÖVE!' on the screen. This includes configuration and the basic game loop functions. ```lua -- conf.lua - Configure game function love.conf(t) t.window.width = 800 t.window.height = 600 t.window.title = "Hello LÖVE" end -- main.lua - Game code function love.load() message = "Hello, LÖVE!" end function love.draw() love.graphics.print(message, 100, 100) end ``` -------------------------------- ### Get Object Type Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/11-types-guide.md Retrieves the type name of an object as a string. Useful for debugging or dynamic type checking. ```lua local image = love.graphics.newImage("sprite.png") print(image:type()) -- Output: Image ``` -------------------------------- ### Set Window Dimensions Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Sets the initial width and height of the game window in pixels. Set to 0 to use desktop/screen dimensions. ```lua function love.conf(t) t.window.width = 1024 t.window.height = 768 end ``` -------------------------------- ### Get Touch Position Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/08-keyboard-mouse-input.md Retrieves the X and Y coordinates of a specific touch point, identified by its ID. Coordinates are normalized (0-1). ```lua function love.touch.getPosition(id: string): (number, number) ``` -------------------------------- ### Get Active Source Count Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Retrieves the number of audio sources that are currently playing. This can be used for monitoring audio activity. ```lua local count = love.audio.getActiveSourceCount() ``` -------------------------------- ### Accessing Configuration at Runtime Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Demonstrates how to store configuration values in a game table within love.conf to access them later in love.load(). Configuration values set in love.conf are not directly accessible after love.load() executes. ```lua -- Store in a game table local game = {} function love.conf(t) game.title = "My Game" t.window.title = game.title end function love.load() print(game.title) -- Still accessible end ``` -------------------------------- ### Get Body Linear Velocity Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Retrieves the current linear velocity of a physics body. Returns the vx and vy components. ```lua vx, vy = body:getLinearVelocity() ``` -------------------------------- ### Configure Resizable Window Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Allows the user to resize the window and sets the minimum width and height for resizable windows. ```lua function love.conf(t) t.window.resizable = true t.window.minwidth = 400 t.window.minheight = 300 end ``` -------------------------------- ### love.physics.getMeter Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/05-physics-module.md Gets the pixel-to-physics scale factor. This is essential for converting between pixel coordinates and the physics engine's meter-based units. ```APIDOC ## love.physics.getMeter ### Description Gets the pixel-to-physics scale factor. This is essential for converting between pixel coordinates and the physics engine's meter-based units. ### Signature ```lua function love.physics.getMeter(): number ``` ### Return Values - **scale** (number) - Pixels per physics meter (default: 32) ### Purpose Box2D works best with object sizes between 0.1 and 10 meters. The meter scale converts between pixel coordinates and physics coordinates: ```lua meter = love.physics.getMeter() -- Default: 32 physicsX = pixelX / meter pixelX = physicsX * meter ``` ### Example ```lua function love.draw() local meter = love.physics.getMeter() for _, body in ipairs(world:getBodys()) do local x, y = body:getPosition() local px = x * meter local py = y * meter -- Draw at pixel coordinates love.graphics.circle('fill', px, py, 5) end end ``` ``` -------------------------------- ### love.filesystem.getDirectoryItems Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/09-filesystem-module.md Lists all files and directories within a specified directory. ```APIDOC ## love.filesystem.getDirectoryItems ### Description Lists files and directories in a directory. ### Signature ```lua function love.filesystem.getDirectoryItems(dir: string): table ``` ### Parameters #### Path Parameters - **dir** (string) - Required - The path to the directory. ### Return Values - **table** - An array of strings, where each string is the name of a file or directory within the specified directory. ### Example ```lua function love.load() local items = love.filesystem.getDirectoryItems("") for _, item in ipairs(items) do print(item) end end ``` ``` -------------------------------- ### Configure Fullscreen Mode Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/03-configuration.md Enables fullscreen mode and specifies the fullscreen type. 'desktop' mode is recommended for borderless fullscreen and multi-monitor behavior. ```lua function love.conf(t) t.window.fullscreen = true t.window.fullscreentype = "desktop" -- "desktop" recommended end ``` -------------------------------- ### Get Active Touch Points Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/08-keyboard-mouse-input.md Retrieves an array of IDs for all currently active touch points on the screen. Useful for iterating over touches. ```lua function love.touch.getTouches(): table ``` -------------------------------- ### Implement Spatial Audio (3D) Source: https://github.com/love2d-community/love-api/blob/master/_autodocs/07-audio-module.md Sets up spatial audio by defining a distance model and updating listener and sound source positions. Volume is automatically adjusted based on distance. ```lua function love.load() sound = love.audio.newSource("effect.wav", "static") love.audio.setDistanceModel('inverseclamped') end function love.update(dt) -- Update listener position (player) love.audio.setPosition(playerX, playerY, 0) -- Update sound position (enemy) sound:setPosition(enemyX, enemyY, 0) -- Play sound with automatic volume based on distance love.audio.play(sound) end ```