Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Flake
An Immediate-Mode game framework
Flake is an immediate-mode game framework and graphics library built on WGPU + Winit. (Inspired by macroquad). Designed to make creating apps and games easier. Supports all three main operating systems with known support for Windows.
Getting Started
Add flake-engine to your Cargo.toml using the following command:
cargo add flake-engine
In your main.rs add the following code to create a window
use *;
async
The #[flake] proc-macro is a shorthand to get you started. Use #[flake("my window")] if you want a window with a
title.
Drawing with Flake
Flake has a global state which means you don't have to get the context for drawing. Just write your drawing functions directly:
loop
Flake includes many drawing functions, the most important being:
clear_background;
draw_text;
draw_rich_text;
draw_rectangle;
draw_rectangle_lines;
draw_circle;
draw_circle_lines;
draw_texture;
draw_arrow;
draw_line;
draw_poly_line;
draw_poly_line_rounded;
draw_triangle;
draw_triangle_lines;
draw_polygon;
draw_polygon_concave;
Window Methods
Flake has many window methods:
get_window;
focus_window;
set_window_x;
set_window_y;
window_position ;
window_position_vec2 ;
set_window_position;
window_width ;
window_height ;
window_size ;
set_window_width;
set_window_height;
set_window_size;
set_window_resizable;
set_window_title;
set_window_passthrough; // whether you can click on the window
set_window_level; // WindowLevel::AlwaysOnTop
set_window_enabled_buttons; // WindowButtons::MAXIMIZE
set_skip_taskbar;
set_window_transparent; // may not work
set_window_decorations;
set_window_visible;
set_window_icon;
set_window_icon_bytes;
// Frames Per Second
get_fps ;
get_frames ;
get_frame_time ; // deltaTime
set_fps_capped; // lets you uncap your FPS
set_target_fps;
Input in Flake
Flake supports mouse and keyboard inputs as of now. Controller support may be added in the future.
Mouse Methods:
mouse_position ;
mouse_position_vec2 ;
mouse_screen_position ;
mouse_screen_position_vec2 ;
mouse_wheel ;
is_mouse_button_down ; // held
is_mouse_button_pressed ; // clicked this frame
is_mouse_button_released ; // released this frame
Keyboard Methods
is_key_down ; // held
is_key_pressed ; // held
is_key_released ; // held
// Returns -1 if left is held and 1 if right is held and 0 if both/none;
get_axis ;
// Returns a Vector2, similar to get_axis() but for 2 axes
get_vector ;
Text in Flake
By default, Flake is bundled with JetBrains Mono 💖. Text also supports using newlines like \n.
draw_text;
Loading Fonts
Load a font using the following:
let my_font = load_font_from_path;
// or
let my_font = load_font_from_bytes;
Please do NOT load fonts inside the loop {} to avoid lag. Fonts are expensive. They should be loaded before the
loop;
You can use a font like this:
draw_text;
Note: Fonts can be clone()'d without any overhead.
RichText
RichText is a section of multiple Spans of text which have their own properties (Text, Color, Font, Size). Useful for
writing text with formatting or for dialog in games. It takes in an iterable of Spans to avoid allocation.
draw_richtext;
Measuring Text
If you need to get the width and height of some text before drawing (Such as for centering/aligning text) you can use
the
measure_text() function.
measure_text ;
Where .x and .y give the width and height respectively.
Textures and Images
Flake supports loading, and writing to Images and drawing textures. Textures support FilterType::Nearest for pixelated
and FilterType::Linear for smooth images. (default = Linear)
Example
// Before the `loop {}`
let my_texture = load_texture;
// Inside `loop {}`
draw_texture;
Loading a Texture
You can load a texture by using these methods:
load_texture;
load_texture_with_filter_type;
// or
load_texture_from_bytes;
load_texture_from_bytes_with_filter_type;
// or
load_texture_from_data // R, G, B, A pixel data from 0-1
load_texture_from_data_with_filter_type;
// or
load_texture_from_image;
Updating a Texture
You can update the data in a Texture using an Image by using the following:
update_texture;
// or
my_texture.update;
Drawing a Texture
draw_texture; // tint the texture using a Color
draw_texture_ex; // DrawTextureParams
Extra texture drawing parameters, called DrawTextureParams allow you to draw
a part of the texture rather than the entire texture and even rotate or flip it.
RenderTarget
A render target is a separate surface on which you can draw. Useful if you want to make a scrolling surface or for clipping some objects.
Instead of drawing to the screen, you can create a camera that uses the render target instead, then switch it back to the default screen camera afterward.
// Create a render target using a width and height
let target = render_target;
let cam = Camera2D ;
It is advised that you create the target and the camera before the loop {}
since creating targets infinitely at runtime will clog memory and speed.
// Draw the RenderTarget's texture at (0, 0) with size (100, 100)
draw_texture;