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 API. Allows creation and manipulation of layers including the primary draw target, a layer 0.

Structs

  • Mirror of olc::Decal. A GPU resident storage of an olc::Sprite.
  • olcPixelGameEngine error.
  • Mirror of olc::HWButton. Represents the button state, either keyboard or mouse.
  • Mirror of olc::Pixel. Represents a 32-bit RGBA value.
  • Mirror of olc::Sprite. An image represented by a 2D array of olc::Pixel.
  • Generic 2D vector type. See Vf2d and Vi2d for more information.

Enums

  • Mirror of olc::Key. Represents a key on a keyboard.
  • Mirror of olc::Pixel::Mode.
  • Mirror of olc::Sprite::Flip.
  • Mirror of olc::Sprite::Mode.

Constants

Traits

  • Application trait, should be extended by an implementation and passed to start function.

Functions

Type Definitions

  • Mirror of olc::vf2d. A 2D float vector type. Implements std::ops::Add, std::ops::Sub, std::ops::Mul, and std::ops::Div as well as all their assignment equivalents.
  • Mirror of olc::vi2d. A 2D integer vector type. Implements std::ops::Add, std::ops::Sub, std::ops::Mul, and std::ops::Div as well as all their assignment equivalents.