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);
}
Expand description

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

Required Methods

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

return the input API to check user mouse and keyboard input

return the current framerate

return the average framerate since the start of the game

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

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.

  • 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.

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

return the current screen size

Implementors