### Lyte2D config.lua example Source: https://lyte2d.com/index.html Example configuration file for Lyte2D. Place it next to app.lua to set window size, title, fullscreen, vsync, and default filter/blend modes before the app loads. Keep it next to the zip or exe when fusing. ```lua return { window_width = 800, window_height = 500, window_title = "my game", fullscreen = false, window_vsync = true, default_filtermode = "nearest", --linear default_blendmode = "blend", } ``` -------------------------------- ### Lyte2D sprite animation example Source: https://lyte2d.com/ Interactive example showing sprite animation using a sprite sheet. Uses dt for time-based movement, input to change sprite tick, and matrix scaling for responsive drawing. ```lua -- lyte sample local total_time = 0 local SCALE = 3 -- image_1 local image_1 = lyte.load_image("assets/hero.png") local sprite_1_tick = 2 local sprite_1_numticks = 5 function lyte.tick(dt, width, height) -- UPDATE -- dt is the time (in seconds) from last tick to now -- keep track of total time total_time = total_time + dt -- control the sprite tick draw with space or left mouse button if lyte.is_key_pressed("space") or lyte.is_mouse_pressed("mb1") then sprite_1_tick = (sprite_1_tick + 1) % sprite_1_numticks end -- scaled down width/height local W = width/SCALE local H = height/SCALE -- x position will change based on time local x_pos = W/2-16/2 + math.sin(total_time)*W/3 -- y position middle of the screen (even when window is resized) local y_pos = H/2-16/2 -- DRAW lyte.cls(0.2, 0.1, 0.1, 1) lyte.push_matrix() lyte.scale(SCALE, SCALE) lyte.draw_image_rect(image_1, x_pos, y_pos, 16*(sprite_1_tick), 0, 16, 16) lyte.pop_matrix() -- background with a "pulsating" alpha lyte.set_color(1,1,1, math.abs(math.sin(total_time/2))) lyte.draw_text("SPACE or LMB: change sprite tick", 10, height-40) end ``` -------------------------------- ### get_mastervolume Source: https://lyte2d.com/ Gets the master volume. ```APIDOC ## get_mastervolume ### Description Gets the master volume. ### Signature `get_mastervolume(): number` ### Returns - **number** - The master volume value. ``` -------------------------------- ### Lyte2D ImageBatch sample Source: https://lyte2d.com/index.html Example of using lyte.ImageBatch to draw multiple sprites from a batch image. It loads an image, creates a batch, adds random rectangles from a 4-sprite sheet, and draws them each tick. Pressing Enter or mouse button 1 resets and regenerates the batch. ```lua -- lyte.ImageBatch sample local img = lyte.load_image("assets/batch.png") local batch = lyte.new_imagebatch(img); local N = 100 local function add_items() for i=1,N do local x = math.random(10, 600) -- location of the destination rectangle local y = math.random(10, 400) local sz = math.random(8,128) -- size of the destination rectangle local r = math.random(1,4) -- one of the 4 sprites will be added if r == 1 then -- dest_x, y, width, height, source_x, y, width, height batch:add_rect(x, y, sz, sz, 0, 0, 32, 32 ) elseif r == 2 then batch:add_rect(x, y, sz, sz, 32, 0, 32, 32 ) elseif r == 3 then batch:add_rect(x, y, sz, sz, 0, 32, 32, 32 ) else batch:add_rect(x, y, sz, sz, 32, 32, 32, 32 ) end end end add_items() function lyte.tick() lyte.cls(0,0,0,1) if lyte.is_key_down("enter") or lyte.is_mouse_down("mb1") then batch:reset() add_items() end batch:draw() end ``` -------------------------------- ### get_textinput Source: https://lyte2d.com/ Gets all keyboard text input from the last frame. Output is UTF-8 encoded. ```APIDOC ## get_textinput ### Description Gets all keyboard text input from the last frame. Output is UTF-8 encoded. ### Signature `get_textinput(): string` ### Returns - **string** - The text input received during the last frame. ``` -------------------------------- ### get_gamepad_count Source: https://lyte2d.com/ Gets the number of connected gamepads. ```APIDOC ## get_gamepad_count ### Description Gets the number of connected gamepads. ### Signature `get_gamepad_count(): int` ### Returns - **int** - The number of gamepads. ``` -------------------------------- ### get_gamepad_name Source: https://lyte2d.com/ Gets the name of the gamepad at the given index. ```APIDOC ## get_gamepad_name ### Description Gets the name of the gamepad at the given index. ### Signature `get_gamepad_name(index: int): string` ### Parameters - **index** (int) - Required - The index of the gamepad. ### Returns - **string** - The name of the gamepad. ``` -------------------------------- ### get_mouse_x Source: https://lyte2d.com/ Gets the current mouse x position. ```APIDOC ## get_mouse_x ### Description Gets the current mouse x position. ### Signature `get_mouse_x(): int` ### Returns - **int** - The x coordinate of the mouse. ``` -------------------------------- ### get_music_volume Source: https://lyte2d.com/ Gets the volume of the given music object. ```APIDOC ## get_music_volume ### Description Gets the volume of the given music object. ### Signature `get_music_volume(music: lyte.Music): number` ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The volume value. ``` -------------------------------- ### set_window_monitor(index) Source: https://lyte2d.com/index.html Sets the window's initial monitor to the indexed value. Must be set before the window is opened. ```APIDOC ## set_window_monitor(index: int) ### Description Set the window's initial monitor to the indexed value. Must be set before the window is opened. ### Parameters - **index** (int) - Required - The monitor index. ### Returns None ``` -------------------------------- ### set_window_size(width, height) Source: https://lyte2d.com/index.html Sets the window's size. ```APIDOC ## set_window_size(width: int, height: int) ### Description Set the window's size. ### Parameters - **width** (int) - Required - Window width. - **height** (int) - Required - Window height. ### Returns None ``` -------------------------------- ### get_mouse_y Source: https://lyte2d.com/ Gets the current mouse y position. ```APIDOC ## get_mouse_y ### Description Gets the current mouse y position. ### Signature `get_mouse_y(): int` ### Returns - **int** - The y coordinate of the mouse. ``` -------------------------------- ### Basic Lyte2D shader with screen_size uniform Source: https://lyte2d.com/index.html Creates a shader program with a screen_size uniform, a vertex shader that passes image UV coordinates, and a fragment shader that modifies color based on screen position and UV. The shader is applied to rectangles and rotated in the tick function. ```lua -- lyte sample local total_time = 0 -- creating a shader program. single argument is a dictionary -- which defines the shader. -- (as of alpha) currently all values need to be passed. local shader_1 = lyte.new_shader({ -- uniforms and their types must be defined beforehand. accepted types: -- float, vec2, vec3, vec4, mat4, int, ivec2, ivec3, ivec4 and sampler2D -- Note: do not declare these inside glsl code. they will be automatically -- added to the proper location. -- by default, two uniforms are passed and can be used in both shaders: -- uniform vec4 current_color --> the value set with lyte.set_color call -- uniform sampler2D current_image --> image set wit lyte.draw_image call uniforms = { screen_size = "vec2", }, -- code for vertex shader. this will be default in a future release -- vert_main function must be defined. gl_Position must be set -- image_uv name is shared between vertex -> fragment shaders -- other can be added by the dev vert = [[ // draw rect sends x, y positions and w/h, 4 floats in vec4 coords; out vec2 image_uv; void vert_main() { gl_Position = vec4(coords.xy, 0.0, 1.0); image_uv = coords.zw; } ]], -- code for fragment shader. -- frag_main function must be defined. -- must output a vec4 value representing rgba -- image_uv name is shared between vertex -> fragment shaders frag = [[ in vec2 image_uv; out vec4 frag_color; void frag_main() { // default fragment shader looks something like the following //frag_color = texture(current_image, image_uv) * current_color; // we'll set blue to depend on the screen X of the pixel frag_color.b = gl_FragCoord.x / screen_size.x; // and red will depend on the texture X and Y of the pixel frag_color.r = image_uv.x * image_uv.y * 2.0; // and green to be the reverse of blue frag_color.g = (1.0 - frag_color.b); frag_color.a = 0.9; } ]] }) local function draw_some_rects(x,y) -- draw some rectangles on different lyte.draw_rect(x+10, y, 60, 20) lyte.draw_rect(x+80, y, 60, 20) lyte.draw_rect(x+150, y, 60, 20) lyte.draw_rect(x+220, y, 60, 20) end function lyte.tick(dt, width, height) -- UPDATE total_time = total_time + dt -- shader_1:set({ screen_size = {width, height} }) shader_1:set("screen_size", {width, height}) -- lyte.set_shader_uniform(shader_1, "screen_size", {width, height}) -- DRAW lyte.cls(0, 0, 0, 1) lyte.reset_color() lyte.set_shader(shader_1) lyte.draw_rect(10, 10, width-20, 40) draw_some_rects(10, 60) draw_some_rects(30, 90) draw_some_rects(60, 120) lyte.push_matrix() lyte.rotate_at(total_time/2, width/2, height/2) lyte.draw_rect(width/2-height/3, height/2-25, height*2/3, 50) lyte.pop_matrix() lyte.reset_shader() end ``` -------------------------------- ### Music Playback with Pitch and Pan Control Source: https://lyte2d.com/index.html Loads a music file and plays it immediately. Adjusts pitch with up/down keys or scroll, pan with left/right keys, and toggles play/pause with right mouse button. Displays playback info and control hints. ```lua -- lyte sample local total_time = 0 -- music local music_1 = lyte.load_music("assets/elev.mp3") -- start playing right away music_1:play() function lyte.tick(dt, width, height) -- UPDATE total_time = total_time + dt -- up/down keys to change the pitch if lyte.is_key_pressed("up") or lyte.is_mouse_pressed("scrollup") then music_1.pitch = (music_1.pitch + 0.01) elseif lyte.is_key_pressed("down") or lyte.is_mouse_pressed("scrolldown")then music_1.pitch = (music_1.pitch - 0.01) end -- left/right keys to change the pan if lyte.is_key_pressed("left") then music_1.pan = math.min(music_1.pan + 0.1, 1) elseif lyte.is_key_pressed("right") then music_1.pan = math.max(music_1.pan - 0.1, 0) end -- rmb start/pause music if lyte.is_mouse_pressed("mb2") then if music_1.playing then music_1:pause() else music_1:play() end end -- DRAW lyte.cls(0.0, 0.1, 0.2, 1) lyte.draw_text(("played: %1.2f/%3.1f secs"):format(music_1.length_played, music_1.length), 10, 10) lyte.draw_text(("pitch: %1.2f, pan: %1.2f "):format(music_1.pitch, music_1.pan), 10, 30) lyte.set_color(1,1,0.2,1) lyte.draw_text("(browser? LMB to enable sound)", 10, height/2-20) lyte.reset_color() lyte.draw_text("RMB to start/pause music", 10, height/2) -- background with a "pulsating" alpha lyte.set_color(0.8,0.9,0.8, math.abs(math.sin(total_time/2))+0.3) lyte.draw_text("Up/Down: change pitch", 10, height-40-20) lyte.set_color(0.9,0.8,0.8, math.abs(math.cos(total_time/2))+0.3) lyte.draw_text("Left/Right: change pan", 10, height-40) end ``` -------------------------------- ### set_window_minsize(width, height) Source: https://lyte2d.com/index.html Sets the window's minimum possible size. ```APIDOC ## set_window_minsize(width: int, height: int) ### Description Set the window's minimum possible size. ### Parameters - **width** (int) - Required - Minimum window width. - **height** (int) - Required - Minimum window height. ### Returns None ``` -------------------------------- ### get_music_pitch Source: https://lyte2d.com/ Gets the pitch of the given music object. ```APIDOC ## get_music_pitch ### Description Gets the pitch of the given music object. ### Signature `get_music_pitch(music: lyte.Music): number` ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The pitch value. ``` -------------------------------- ### get_music_pan Source: https://lyte2d.com/ Gets the pan of the given music object. ```APIDOC ## get_music_pan ### Description Gets the pan of the given music object. ### Signature `get_music_pan(music: lyte.Music): number` ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The pan value. ``` -------------------------------- ### Lyte2D drawing primitives sample (s01_hello) Source: https://lyte2d.com/index.html Interactive sample demonstrating image loading, color management, and drawing primitives: rectangles, circles, lines, points, triangles, ellipses, and text. Uses push_matrix/scale/pop_matrix for transformations and draw_image_rect for sprite portions. Note the comment about version 0.7.4 adding new drawing primitives. ```lua -- lyte sample -- load an image local image_1 = lyte.load_image("assets/hero.png") function lyte.tick(dt, width, height) -- background color lyte.cls(0, 0, 0, 1) -- foreground color for the rectangles, red with alpha lyte.set_color(1, 0, 0, 0.3) -- draw 4 filled overlapping rectangles for i=1,4 do local x = i * width/7 local y = i * height/7 lyte.draw_rect(x, y, width/3, height/3) end -- foreground color for the circles, green with alpha lyte.set_color(0, 1, 0, 0.3) -- draw 4 filled overlapping circles for i=1,4 do local x = width - ((i+1) * width/7) local y = i * height/7 lyte.draw_circle(x, y, (width+height)/6) end lyte.set_color(1,1,0,1) lyte.draw_circle_line(width/2, height/2, (width+height)/4); lyte.reset_color() -- sets color to: (1, 1, 1, 1) -- draw the text on the top lyte.draw_text("Hello, Lyte2D", 4, 4) -- draw the image lyte.draw_image(image_1, 10, 50) -- draw the image, scaled lyte.push_matrix() lyte.scale(2, 2) -- full image lyte.draw_image(image_1, 10, 70) -- a portion of the image (sprite's ticks are 16x16. draw #3) lyte.draw_image_rect(image_1, 10, 90, 16*(3-1), 0, 16, 16) -- 0.7.4: new drawing primitives lyte.draw_line(10,10,100,100) lyte.draw_point(102,102) lyte.draw_triangle_line(150,50,154,100, 220,100) lyte.draw_triangle(150,150,154,200, 220,200) lyte.draw_ellipse(250, 50, 30, 10) lyte.draw_ellipse_line(220, 50, 30, 10) lyte.draw_ellipse(250, 150, 10, 40) lyte.draw_ellipse_line(220, 150, 6, 30) lyte.pop_matrix() end ``` -------------------------------- ### load_font(font_path, size) Source: https://lyte2d.com/index.html Loads a font from the specified path and sets the initial size. ```APIDOC ## load_font(font_path: string, size: number): lyte.Font ### Description Load the font specified in the path, and set the initial size. ### Parameters - **font_path** (string) - Required - Path to the font file. - **size** (number) - Required - Initial font size. ### Returns - **lyte.Font** - The loaded font object. ``` -------------------------------- ### Hello world in Lyte2D Source: https://lyte2d.com/index.html Minimal Lyte2D program that draws the text 'Hello, world' at coordinates (0, 0) on each tick. The lyte.tick function is the main game loop callback. ```lua function lyte.tick() lyte.draw_text("Hello, world", 0, 0) end ``` -------------------------------- ### new_shader Source: https://lyte2d.com/index.html Creates a shader with the given specification. ```APIDOC ## new_shader ### Description Creates a shader with given specification. ### Function Signature `new_shader(shaderdef: lyte.ShaderDef): lyte.Shader` ### Parameters - **shaderdef** (lyte.ShaderDef) - Required - The shader definition. ### Returns - **lyte.Shader** - The created shader. ``` -------------------------------- ### get_pressed_keys Source: https://lyte2d.com/ Gets the list of currently pressed keys. ```APIDOC ## get_pressed_keys ### Description Gets the list of currently pressed keys. ### Signature `get_pressed_keys(): lyte.KeyList` ### Returns - **lyte.KeyList** - A list of pressed keys. ``` -------------------------------- ### Window Functions Source: https://lyte2d.com/index.html Functions to manage the window, including vsync, icon, margins, and paddings. ```APIDOC ## is_window_vsync ### Description Returns whether the window is in vsync mode. ### Method function ### Signature is_window_vsync(): boolean ### Returns - **boolean** - True if vsync is enabled, false otherwise. ## set_window_icon_file ### Description Sets the window icon from the specified file path. ### Method function ### Signature set_window_icon_file(icon_path: string) ### Parameters - **icon_path** (string) - Required - Path to the icon file. ## set_window_margins ### Description Sets the window margins. Margins are ignored and no drawing can be made there. ### Method function ### Signature set_window_margins(left: int, right: int, top: int, bottom: int) ### Parameters - **left** (int) - Required - Left margin size. - **right** (int) - Required - Right margin size. - **top** (int) - Required - Top margin size. - **bottom** (int) - Required - Bottom margin size. ## set_window_paddings ### Description Sets the window paddings. Paddings can be drawn on. ### Method function ### Signature set_window_paddings(left: int, right: int, top: int, bottom: int) ### Parameters - **left** (int) - Required - Left padding size. - **right** (int) - Required - Right padding size. - **top** (int) - Required - Top padding size. - **bottom** (int) - Required - Bottom padding size. ``` -------------------------------- ### get_music_length Source: https://lyte2d.com/ Gets the length of the given music object in seconds. ```APIDOC ## get_music_length ### Description Gets the length of the given music object in seconds. ### Signature `get_music_length(music: lyte.Music): number` ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The length in seconds. ``` -------------------------------- ### load_sound Source: https://lyte2d.com/ Loads the sound file specified in the path. ```APIDOC ## load_sound ### Description Loads the sound file specified in the path. ### Signature `load_sound(sound_path: string): lyte.Sound` ### Parameters - **sound_path** (string) - Required - Path to the sound file. ### Returns - **lyte.Sound** - A sound object. ``` -------------------------------- ### load_music Source: https://lyte2d.com/ Loads the music file specified in the path. ```APIDOC ## load_music ### Description Loads the music file specified in the path. ### Signature `load_music(music_path: string): lyte.Music` ### Parameters - **music_path** (string) - Required - Path to the music file. ### Returns - **lyte.Music** - A music object. ``` -------------------------------- ### get_gamepad_axis Source: https://lyte2d.com/ Gets the value of the given axis of the gamepad at the given index. ```APIDOC ## get_gamepad_axis ### Description Gets the value of the given axis of the gamepad at the given index. ### Signature `get_gamepad_axis(index: int, gamepad_axis: lyte.GamepadAxis): number` ### Parameters - **index** (int) - Required - The index of the gamepad. - **gamepad_axis** (lyte.GamepadAxis) - Required - The axis to query. ### Returns - **number** - The axis value. ``` -------------------------------- ### set_fullscreen(fullscreen) Source: https://lyte2d.com/index.html Sets the window to fullscreen or windowed mode. ```APIDOC ## set_fullscreen(fullscreen: boolean) ### Description Set the window to fullscreen, or windowed mode. ### Parameters - **fullscreen** (boolean) - Required - True for fullscreen, false for windowed. ### Returns None ``` -------------------------------- ### get_music_length_played Source: https://lyte2d.com/ Gets the already played length of the given music object in seconds. ```APIDOC ## get_music_length_played ### Description Gets the already played length of the given music object in seconds. ### Signature `get_music_length_played(music: lyte.Music): number` ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The played length in seconds. ``` -------------------------------- ### resume_music Source: https://lyte2d.com/ Resumes the given music object. ```APIDOC ## resume_music ### Description Resumes the given music object. ### Signature `resume_music(music: lyte.Music)` ### Parameters - **music** (lyte.Music) - Required - The music object to resume. ``` -------------------------------- ### Sound Effects with Multiple Instances and Panning Source: https://lyte2d.com/index.html Loads two sound effects and creates multiple playable instances with different pan positions. Triggers sounds via mouse buttons and keys 1/2/3. Notes that browser sounds may be delayed. ```lua -- lyte sample local sfx_hurt = lyte.load_sound("assets/sfx_hurt.wav") local sfx_shoot = lyte.load_sound("assets/sfx_shoot.ogg") -- sound fx: playable instances -- 3 'hurt' instances local sfx_hurt_1 = lyte.clone_sound(sfx_hurt) local sfx_hurt_2 = lyte.clone_sound(sfx_hurt) local sfx_hurt_3 = lyte.clone_sound(sfx_hurt) -- 2 'shoot' instances local sfx_shoot_1 = lyte.clone_sound(sfx_shoot) local sfx_shoot_2 = lyte.clone_sound(sfx_shoot) -- pans on both sides and middle sfx_hurt_1.pan = 1.0 sfx_hurt_2.pan = 0.5 sfx_hurt_3.pan = 0.0 -- pans on both sides sfx_shoot_1.pan = 1.0 sfx_shoot_2.pan = 0.0 function lyte.tick(dt, width, height) -- UPDATE -- lmb/rmb for shooting sounds if lyte.is_mouse_pressed("mb1") then sfx_shoot_1:play() end if lyte.is_mouse_pressed("mb2") then sfx_shoot_2:play() end -- keys 1/2/3 for hurting sounds if lyte.is_key_pressed("1") then sfx_hurt_1:play() end if lyte.is_key_pressed("2") then sfx_hurt_2:play() end if lyte.is_key_pressed("3") then sfx_hurt_3:play() end -- DRAW lyte.cls(0.0, 0.15, 0.05, 1) lyte.draw_text("Sounds FX", 10, 10) lyte.draw_text("LMB/RMB for 'shooting'", 10, 60) lyte.draw_text("1/2/3 for 'hurting'", 10, 80) lyte.set_color(1, 1, 0, 1) lyte.draw_text("(on browser, sounds can be delayed)", 5, 120) end ``` -------------------------------- ### Gamepad Input Functions Source: https://lyte2d.com/index.html Functions to query gamepad presence, buttons, and axes. ```APIDOC ## get_gamepad_count ### Description Gets the number of connected gamepads. ### Method function ### Signature get_gamepad_count(): int ### Returns - **int** - The number of gamepads. ## get_gamepad_name ### Description Gets the name of the gamepad at the given index. ### Method function ### Signature get_gamepad_name(index: int): string ### Parameters - **index** (int) - Required - The index of the gamepad. ### Returns - **string** - The name of the gamepad. ## is_gamepad_down ### Description Checks if the given button of the gamepad at the given index is currently down. ### Method function ### Signature is_gamepad_down(index: int, gamepad_button: lyte.GamepadButton): boolean ### Parameters - **index** (int) - Required - The index of the gamepad. - **gamepad_button** (lyte.GamepadButton) - Required - The button to check. ### Returns - **boolean** - True if the button is down, false otherwise. ## is_gamepad_pressed ### Description Checks if the given button of the gamepad at the given index was pressed in the current frame. ### Method function ### Signature is_gamepad_pressed(index: int, gamepad_button: lyte.GamepadButton): boolean ### Parameters - **index** (int) - Required - The index of the gamepad. - **gamepad_button** (lyte.GamepadButton) - Required - The button to check. ### Returns - **boolean** - True if the button was pressed, false otherwise. ## is_gamepad_released ### Description Checks if the given button of the gamepad at the given index was released in the current frame. ### Method function ### Signature is_gamepad_released(index: int, gamepad_button: lyte.GamepadButton): boolean ### Parameters - **index** (int) - Required - The index of the gamepad. - **gamepad_button** (lyte.GamepadButton) - Required - The button to check. ### Returns - **boolean** - True if the button was released, false otherwise. ## get_gamepad_axis ### Description Gets the value of the given axis of the gamepad at the given index. ### Method function ### Signature get_gamepad_axis(index: int, gamepad_axis: lyte.GamepadAxis): number ### Parameters - **index** (int) - Required - The index of the gamepad. - **gamepad_axis** (lyte.GamepadAxis) - Required - The axis to query. ### Returns - **number** - The axis value. ``` -------------------------------- ### Audio Functions Source: https://lyte2d.com/index.html Functions for master volume, music, and sound playback. ```APIDOC ## set_mastervolume ### Description Sets the master volume. ### Method function ### Signature set_mastervolume(mastervolume: number) ### Parameters - **mastervolume** (number) - Required - The master volume value. ## get_mastervolume ### Description Gets the master volume. ### Method function ### Signature get_mastervolume(): number ### Returns - **number** - The master volume value. ## load_music ### Description Loads the music file specified by the path. ### Method function ### Signature load_music(music_path: string): lyte.Music ### Parameters - **music_path** (string) - Required - Path to the music file. ### Returns - **lyte.Music** - The loaded music object. ## play_music ### Description Plays the given music object. ### Method function ### Signature play_music(music: lyte.Music) ### Parameters - **music** (lyte.Music) - Required - The music object to play. ## pause_music ### Description Pauses the given music object. ### Method function ### Signature pause_music(music: lyte.Music) ### Parameters - **music** (lyte.Music) - Required - The music object to pause. ## resume_music ### Description Resumes the given music object. ### Method function ### Signature resume_music(music: lyte.Music) ### Parameters - **music** (lyte.Music) - Required - The music object to resume. ## stop_music ### Description Stops the given music object. ### Method function ### Signature stop_music(music: lyte.Music) ### Parameters - **music** (lyte.Music) - Required - The music object to stop. ## is_music_playing ### Description Checks if the given music object is currently playing. ### Method function ### Signature is_music_playing(music: lyte.Music): boolean ### Parameters - **music** (lyte.Music) - Required - The music object to check. ### Returns - **boolean** - True if playing, false otherwise. ## get_music_length ### Description Gets the length of the given music object in seconds. ### Method function ### Signature get_music_length(music: lyte.Music): number ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The length in seconds. ## get_music_length_played ### Description Gets the already played length of the given music object in seconds. ### Method function ### Signature get_music_length_played(music: lyte.Music): number ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The played length in seconds. ## seek_music ### Description Moves the music time played to the given value. ### Method function ### Signature seek_music(music: lyte.Music, secs: number) ### Parameters - **music** (lyte.Music) - Required - The music object. - **secs** (number) - Required - The target time in seconds. ## set_music_volume ### Description Sets the volume of the given music object. ### Method function ### Signature set_music_volume(music: lyte.Music, volume: number) ### Parameters - **music** (lyte.Music) - Required - The music object. - **volume** (number) - Required - The volume value. ## set_music_pan ### Description Sets the pan of the given music object. ### Method function ### Signature set_music_pan(music: lyte.Music, pan: number) ### Parameters - **music** (lyte.Music) - Required - The music object. - **pan** (number) - Required - The pan value. ## set_music_pitch ### Description Sets the pitch of the given music object. ### Method function ### Signature set_music_pitch(music: lyte.Music, pitch: number) ### Parameters - **music** (lyte.Music) - Required - The music object. - **pitch** (number) - Required - The pitch value. ## get_music_volume ### Description Gets the volume of the given music object. ### Method function ### Signature get_music_volume(music: lyte.Music): number ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The volume value. ## get_music_pan ### Description Gets the pan of the given music object. ### Method function ### Signature get_music_pan(music: lyte.Music): number ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The pan value. ## get_music_pitch ### Description Gets the pitch of the given music object. ### Method function ### Signature get_music_pitch(music: lyte.Music): number ### Parameters - **music** (lyte.Music) - Required - The music object. ### Returns - **number** - The pitch value. ## load_sound ### Description Loads the sound file specified by the path. ### Method function ### Signature load_sound(sound_path: string): lyte.Sound ### Parameters - **sound_path** (string) - Required - Path to the sound file. ### Returns - **lyte.Sound** - The loaded sound object. ## clone_sound ### Description Clones the given sound object. ### Method function ### Signature clone_sound(orig: lyte.Sound): lyte.Sound ### Parameters - **orig** (lyte.Sound) - Required - The original sound object. ### Returns - **lyte.Sound** - A clone of the sound object. ## play_sound ### Description Plays the given sound object. ### Method function ### Signature play_sound(sound: lyte.Sound) ### Parameters - **sound** (lyte.Sound) - Required - The sound object to play. ## pause_sound ### Description Pauses the given sound object. ### Method function ### Signature pause_sound(sound: lyte.Sound) ### Parameters - **sound** (lyte.Sound) - Required - The sound object to pause. ## resume_sound ### Description Resumes the given sound object. ### Method function ### Signature resume_sound(sound: lyte.Sound) ### Parameters - **sound** (lyte.Sound) - Required - The sound object to resume. ## stop_sound ### Description Stops the given sound object. ### Method function ### Signature stop_sound(sound: lyte.Sound) ### Parameters - **sound** (lyte.Sound) - Required - The sound object to stop. ## is_sound_playing ### Description Checks if the given sound object is currently playing. ### Method function ### Signature is_sound_playing(sound: lyte.Sound): boolean ### Parameters - **sound** (lyte.Sound) - Required - The sound object to check. ### Returns - **boolean** - True if playing, false otherwise. ## set_sound_volume ### Description Sets the volume of the given sound object. ### Method function ### Signature set_sound_volume(sound: lyte.Sound, volume: number) ### Parameters - **sound** (lyte.Sound) - Required - The sound object. - **volume** (number) - Required - The volume value. ## set_sound_pan ### Description Sets the pan of the given sound object. ### Method function ### Signature set_sound_pan(sound: lyte.Sound, pan: number) ### Parameters - **sound** (lyte.Sound) - Required - The sound object. - **pan** (number) - Required - The pan value. ## set_sound_pitch ### Description Sets the pitch of the given sound object. ### Method function ### Signature set_sound_pitch(sound: lyte.Sound, pitch: number) ### Parameters - **sound** (lyte.Sound) - Required - The sound object. - **pitch** (number) - Required - The pitch value. ``` -------------------------------- ### is_fullscreen() Source: https://lyte2d.com/index.html Checks if the window is set to fullscreen. ```APIDOC ## is_fullscreen(): boolean ### Description Check if the window is set to fullscreen. ### Parameters None ### Returns - **boolean** - True if fullscreen, false otherwise. ``` -------------------------------- ### set_window_title(title) Source: https://lyte2d.com/index.html Sets the window's title. ```APIDOC ## set_window_title(title: string) ### Description Set the window's title. ### Parameters - **title** (string) - Required - The new window title. ### Returns None ``` -------------------------------- ### new_imagebatch(image) Source: https://lyte2d.com/index.html Creates a new image batch from the given image. ```APIDOC ## new_imagebatch(image: lyte.Image): lyte.ImageBatch ### Description Create an image batch. ### Parameters - **image** (lyte.Image) - Required - The source image for the batch. ### Returns - **lyte.ImageBatch** - The created image batch. ``` -------------------------------- ### draw_imagebatch(imagebatch) Source: https://lyte2d.com/index.html Draws the image batch. ```APIDOC ## draw_imagebatch(imagebatch: lyte.ImageBatch) ### Description Draw the image batch. ### Parameters - **imagebatch** (lyte.ImageBatch) - Required - The image batch to draw. ### Returns None ``` -------------------------------- ### load_image(image_path) Source: https://lyte2d.com/index.html Loads an image from the specified path and returns a lyte.Image object. ```APIDOC ## load_image(image_path: string): lyte.Image ### Description Load the image specified in the path. ### Parameters - **image_path** (string) - Required - Path to the image file. ### Returns - **lyte.Image** - The loaded image object. ``` -------------------------------- ### set_window_resizable(resizable) Source: https://lyte2d.com/index.html Sets the window resizable flag to the given value. Must be set before the window is opened. ```APIDOC ## set_window_resizable(resizable: boolean) ### Description Set the window resizable flag to the given value. Must be set before the window is opened. ### Parameters - **resizable** (boolean) - Required - Whether the window should be resizable. ### Returns None ``` -------------------------------- ### resume_sound Source: https://lyte2d.com/ Resumes the given sound object. ```APIDOC ## resume_sound ### Description Resumes the given sound object. ### Signature `resume_sound(sound: lyte.Sound)` ### Parameters - **sound** (lyte.Sound) - Required - The sound object to resume. ``` -------------------------------- ### load_textfile Source: https://lyte2d.com/index.html Loads the content of a text file from the given path. ```APIDOC ## load_textfile ### Description Loads the file in the path. ### Function Signature `load_textfile(file_path: string): string` ### Parameters - **file_path** (string) - Required - The path to the text file to load. ### Returns - **string** - The content of the file. ``` -------------------------------- ### Lyte2D sprite animation sample (s02_movement) Source: https://lyte2d.com/index.html Interactive sample showing sprite animation with time-based movement and input handling. Uses lyte.is_key_pressed and lyte.is_mouse_pressed to advance a sprite tick, and scales the drawing with push_matrix/scale/pop_matrix. The sprite tick is controlled by SPACE or left mouse button. ```lua -- lyte sample local total_time = 0 local SCALE = 3 -- image_1 local image_1 = lyte.load_image("assets/hero.png") local sprite_1_tick = 2 local sprite_1_numticks = 5 function lyte.tick(dt, width, height) -- UPDATE -- dt is the time (in seconds) from last tick to now -- keep track of total time total_time = total_time + dt -- control the sprite tick draw with space or left mouse button if lyte.is_key_pressed("space") or lyte.is_mouse_pressed("mb1") then sprite_1_tick = (sprite_1_tick + 1) % sprite_1_numticks end -- scaled down width/height local W = width/SCALE local H = height/SCALE -- x position will change based on time local x_pos = W/2-16/2 + math.sin(total_time)*W/3 -- y position middle of the screen (even when window is resized) local y_pos = H/2-16/2 -- DRAW lyte.cls(0.2, 0.1, 0.1, 1) lyte.push_matrix() lyte.scale(SCALE, SCALE) lyte.draw_image_rect(image_1, x_pos, y_pos, 16*(sprite_1_tick), 0, 16, 16) lyte.pop_matrix() -- background with a "pulsating" alpha lyte.set_color(1,1,1, math.abs(math.sin(total_time/2))) lyte.draw_text("SPACE or LMB: change sprite tick", 10, height-40) end ``` -------------------------------- ### push_matrix Source: https://lyte2d.com/index.html Pushes the current transformation matrix onto the stack. ```APIDOC ## push_matrix ### Description Pushes the transform matrix. ### Function Signature `push_matrix()` ### Parameters - None ### Returns - None ``` -------------------------------- ### set_window_icon_file Source: https://lyte2d.com/ Sets the window icon from an image file. ```APIDOC ## set_window_icon_file ### Description Sets the window icon from an image file. ### Signature `set_window_icon_file(icon_path: string)` ### Parameters - **icon_path** (string) - Required - Path to the icon image file. ``` -------------------------------- ### scale_at Source: https://lyte2d.com/index.html Applies scaling at a specified location to the current transformation matrix. ```APIDOC ## scale_at ### Description Applies scaling at the given location (changes transform matrix). ### Function Signature `scale_at(scale_x: number, scale_y: number, x: number, y: number)` ### Parameters - **scale_x** (number) - Required - The scaling factor along the x-axis. - **scale_y** (number) - Required - The scaling factor along the y-axis. - **x** (number) - Required - The x-coordinate of the scaling center. - **y** (number) - Required - The y-coordinate of the scaling center. ### Returns - None ``` -------------------------------- ### get_window_height() Source: https://lyte2d.com/index.html Returns the height of the window. ```APIDOC ## get_window_height(): int ### Description Get the height of the window. ### Parameters None ### Returns - **int** - The height of the window in pixels. ```