Expand description
olcPixelGameEngine Rust API.
See documentation on the invidual structs, enums, and functions for more information.
All of the root API functions and drawing routines are normally called as
olc::<function>(...)
similar to C++ code.
Here is an example that shows how to implement Application
trait and call
olcPixelGameEngine drawing functions.
extern crate olc_pixel_game_engine;
use crate::olc_pixel_game_engine as olc;
// Very simple example application that prints "Hello, World!" on screen.
struct ExampleProgram {}
impl olc::Application for ExampleProgram {
fn on_user_create(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserCreate`. Your code goes here.
Ok(())
}
fn on_user_update(&mut self, _elapsed_time: f32) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserUpdate`. Your code goes here.
// Clears screen and sets black colour.
olc::clear(olc::BLACK);
// Prints the string starting at the position (40, 40) and using white colour.
olc::draw_string(40, 40, "Hello, World!", olc::WHITE)?;
Ok(())
}
fn on_user_destroy(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserDestroy`. Your code goes here.
Ok(())
}
}
fn main() {
let mut example = ExampleProgram {};
// Launches the program in 200x100 "pixels" screen, where each "pixel" is 4x4 pixel square,
// and starts the main game loop.
olc::start("Hello, World!", &mut example, 200, 100, 4, 4).unwrap();
}
Modules§
- layer
- Layer API. Allows creation and manipulation of layers including the primary draw target, a layer 0.
Structs§
- Decal
- Mirror of
olc::Decal
. A GPU resident storage of anolc::Sprite
. - Error
- olcPixelGameEngine error.
- HWButton
- Mirror of
olc::HWButton
. Represents the button state, either keyboard or mouse. - Pixel
- Mirror of
olc::Pixel
. Represents a 32-bit RGBA value. - Sprite
- Mirror of
olc::Sprite
. An image represented by a 2D array ofolc::Pixel
. - V2d
- Generic 2D vector type. See
Vf2d
andVi2d
for more information.
Enums§
- Key
- Mirror of
olc::Key
. Represents a key on a keyboard. - Pixel
Mode - Mirror of
olc::Pixel::Mode
. - Sprite
Flip - Mirror of
olc::Sprite::Flip
. - Sprite
Mode - Mirror of
olc::Sprite::Mode
.
Constants§
- BLACK
- BLANK
- BLUE
- CYAN
- DARK_
BLUE - DARK_
CYAN - DARK_
GREEN - DARK_
GREY - DARK_
MAGENTA - DARK_
RED - DARK_
YELLOW - GREEN
- GREY
- MAGENTA
- RED
- VERY_
DARK_ BLUE - VERY_
DARK_ CYAN - VERY_
DARK_ GREEN - VERY_
DARK_ GREY - VERY_
DARK_ MAGENTA - VERY_
DARK_ RED - VERY_
DARK_ YELLOW - WHITE
- YELLOW
Traits§
- Application
- Application trait, should be extended by an implementation and passed to
start
function.
Functions§
- c_rand
- Utility C++ rand function, equivalent of
rand()
. See http://www.cplusplus.com/reference/cstdlib/rand for more information. - c_srand
- Sets seed for C++ rand function, equivalent of
srand(seed)
. See http://www.cplusplus.com/reference/cstdlib/srand for more information. - clear
- Clears entire draw target to Pixel.
- clear_
buffer - Clears the rendering back buffer.
- draw
- Draws pixel at coordinates (x, y).
- draw_
circle - Draws a circle located at (x, y) with radius.
- draw_
circle_ with_ mask - Draws a circle located at (x, y) with radius. Allows to set mask.
- draw_
decal - Draws a whole decal with default scale and tinting.
- draw_
decal_ ext - Draws a whole decal with scale and tinting.
- draw_
line - Draws a line from (x1, y1) to (x2, y2).
- draw_
line_ with_ pattern - Draws a line from (x1, y1) to (x2, y2). Allows to set pattern.
- draw_
partial_ decal - Draws a region of a decal with default scale and tint.
- draw_
partial_ decal_ ext - Draws a region of a decal with scale and tinting.
- draw_
partial_ rotated_ decal - Draws partial rotated decal with default scale and tinting.
- draw_
partial_ rotated_ decal_ ext - Draws partial rotated decal.
- draw_
partial_ sprite - Draws an area of a sprite at location (x, y), where the selected area is (ox, oy) to (ox+w, oy+h).
- draw_
partial_ sprite_ ext - Draws an area of a sprite at location (x, y), where the selected area is (ox, oy) to (ox+w, oy+h) with provided scale and flip.
- draw_
partial_ warped_ decal - Draws partial warped decal with default tinting.
pos
is an array of 4 positions. - draw_
partial_ warped_ decal_ ext - Draws partial warped decal.
pos
is an array of 4 positions. - draw_
rect - Draws a rectangle at (x, y) to (x+w, y+h).
- draw_
rotated_ decal - Draws rotated decal with default center, scale, and tinting.
- draw_
rotated_ decal_ ext - Draws rotated decal with custom center, scale, and tinting.
- draw_
sprite - Draws an entire sprite at the location (x, y).
- draw_
sprite_ ext - Draws an entire sprite at the location (x, y) with provided scale and flip.
- draw_
string - Draws string.
- draw_
string_ decal - Draws string decal with default colour and scale.
- draw_
string_ decal_ ext - Draws string decal with colour and scale.
- draw_
string_ with_ scale - Draws string. Allows to set scale.
- draw_
triangle - Draws a triangle between points (x1, y1), (x2, y2) and (x3, y3).
- draw_
warped_ decal - Draws warped decal with default tinting.
pos
is an array of 4 positions. - draw_
warped_ decal_ ext - Draws warped decal.
pos
is an array of 4 positions. - fill_
circle - Fills a circle located at (x, y) with radius.
- fill_
rect - Fills a rectangle at (x, y) to (x+w, y+h).
- fill_
triangle - Flat fills a triangle between points (x1, y1), (x2, y2) and (x3, y3).
- get_
draw_ target_ height - Returns the height of the currently selected drawing target in “pixels”.
- get_
draw_ target_ width - Returns the width of the currently selected drawing target in “pixels”.
- get_fps
- Gets the current Frames Per Second.
- get_key
- Returns the state of a specific keyboard button.
- get_
mouse - Returns the state of a specific mouse button.
- get_
mouse_ wheel - Returns mouse wheel delta.
- get_
mouse_ x - Returns mouse X coordinate in “pixel” space.
- get_
mouse_ y - Returns mouse Y coordinate in “pixel” space.
- get_
pixel_ mode - Returns the current pixel mode.
- is_
focused - Whether or not the window is focused.
- screen_
height - Returns the height of the screen in “pixels”.
- screen_
width - Returns the width of the screen in “pixels”.
- set_
pixel_ blend - Changes the blend factor form between 0.0f to 1.0f.
- set_
pixel_ mode - Changes the pixel mode for different optimisations.
- set_
screen_ size - Resizes the primary screen sprite.
- start
- Starts the main game loop.
- start_
with_ full_ screen_ and_ vsync - Starts the main game loop with configurable full screen and vsync.
Type Aliases§
- Vf2d
- Mirror of
olc::vf2d
. A 2D float vector type. Implementsstd::ops::Add
,std::ops::Sub
,std::ops::Mul
, andstd::ops::Div
as well as all their assignment equivalents. - Vi2d
- Mirror of
olc::vi2d
. A 2D integer vector type. Implementsstd::ops::Add
,std::ops::Sub
,std::ops::Mul
, andstd::ops::Div
as well as all their assignment equivalents.