Rendering
Required version: Sponge >=1.0.4
sdl2.clear_screen()
Clears the entire screen with the current draw color (default black). This should be called at the beginning of each frame.
Parameters: None
Returns: null
Example:
while sdl2.is_window_open() {
sdl2.clear_screen();
# ... draw your content ...
sdl2.render_present();
}sdl2.render_present()
Updates the screen with all drawn content and handles window events. This should be called at the end of each frame. Also updates the delta time for the next frame.
Parameters: None
Returns: null
Example:
sdl2.clear_screen();
sdl2.draw_circle(100, 100, 50);
sdl2.render_present();sdl2.set_draw_color(red, green, blue)
Sets the color for all subsequent drawing operations.
Parameters:
red(number) - Red component (0-255)green(number) - Green component (0-255)blue(number) - Blue component (0-255)
Returns: null
Example:
# Set color to red
sdl2.set_draw_color(255, 0, 0);
# Set color to green
sdl2.set_draw_color(0, 255, 0);
# Set color to blue
sdl2.set_draw_color(0, 0, 255);
# Set color to white
sdl2.set_draw_color(255, 255, 255);sdl2.set_max_fps(fps)
Required version: Sponge >=1.0.6
Locks the frame rate to a maximum FPS (frames per second). This ensures consistent performance across different computers. The renderer will sleep if a frame finishes too quickly to maintain the target FPS.
Parameters:
fps(number) - Target frames per second (must be greater than 0)
Returns: null
Example:
sdl2.set_max_fps(60); # Lock to 60 FPSsdl2.delta_time()
Required version: Sponge >=1.0.6
Returns the time elapsed since the last frame in seconds. This is essential for frame-rate independent movement and animations.
Parameters: None
Returns: float - Time in seconds since the last sdl2.render_present() call
Example:
let dt = sdl2.delta_time();
let movement = speed * dt; # Move at consistent speed regardless of FPS