[][src]Trait doryen_rs::DoryenApi

pub trait DoryenApi {
    fn con(&mut self) -> &mut Console;
fn input(&mut self) -> &mut dyn InputApi;
fn fps(&self) -> u32;
fn average_fps(&self) -> u32;
fn set_font_path(&mut self, font_path: &str);
fn get_screen_size(&self) -> (u32, u32); }

This is the complete doryen-rs API provided to you by App in Engine::update and Engine::render methods.

Required methods

fn con(&mut self) -> &mut Console

return the root console that you can use to draw things on the screen

fn input(&mut self) -> &mut dyn InputApi

return the input API to check user mouse and keyboard input

fn fps(&self) -> u32

return the current framerate

fn average_fps(&self) -> u32

return the average framerate since the start of the game

fn set_font_path(&mut self, font_path: &str)

replace the current font by a new one. Put your font in the static/ directory of the project to make this work with both cargo run and cargo web start. Example

This example deliberately fails to compile
api.set_font_path("terminal.png");

During development, this references $PROJECT_ROOT/static/terminal.png. Once deployed, terminal.png should be in the same directory as your game's executable or index.html.

By default, doryen-rs will assume the font has a 16x16 extended ASCII layout. The character size will be calculated with :

char_width = font_image_width / 16
char_height = font_image_height / 16

If your font has a different layout (that's the case in the unicode example), you have to provide the character size by appending it to the font file name :

myfont_8x8.png

doryen_rs support several font format. It uses the top left pixel of the font to determin the format.

  • If the top-left pixel alpha value is < 255, this is an RGBA font.

  • If the top-left pixel alpha value is 255 and its color is black, this is a greyscale font.

  • Else, it's an RGB font.

  • RGBA : transparency is stored in alpha channel. It can have semi-transparent pixels of any color. The picture below shows on the left the font image and on the right how it appears when the characters are drawn on a blue background. rgba

  • greyscale : black pixels are transparent. Grey pixels are replaced by white semi-transparent pixels. Colored pixels are opaque. The font cannot have pure grey colors. greyscale

  • RGB : The top-left pixel's color is transparent. The font cannot have semi-transparent pixels but it can have pure grey pixels. rgb

fn get_screen_size(&self) -> (u32, u32)

return the current screen size

Loading content...

Implementors

Loading content...