[][src]Struct crystal_engine::GameState

pub struct GameState {
    pub camera: Matrix4<f32>,
    pub keyboard: KeyboardState,
    pub light: LightState,
    // some fields omitted
}

Contains the game state. This struct is passed to Game::init and Game::update.

Fields

camera: Matrix4<f32>

The matrix of the camera currently in use.

It is currently not possible to change the near and far boundaries of the camera. This might be added in a later version.

keyboard: KeyboardState

Get the current keyboard state.

light: LightState

The state of the lights currently in the world.

Implementations

impl GameState[src]

pub fn load_font(
    &mut self,
    font: impl AsRef<Path>
) -> Result<Font<'static>, GuiError>
[src]

Load a font from the given relative path. This function will panic if the font does not exist.

The font is not stored internally, and must be stored by the developer.

pub fn window(&self) -> &Window[src]

Get a reference to the winit window. This can be used to set the title with set_title, grap the cursor with set_cursor_grab and set_cursor_visible, and more.

pub fn set_cursor_position<P: Pixel>(&self, position: (P, P))[src]

Set the cursor position. This is short for:

state.window()
     .set_cursor_position(winit::dpi::PhysicalPosition::new(0u32, 0u32))
     .unwrap();

Platform-specific

On iOS this always returns an error, so this function is empty

pub fn terminate_game(&mut self)[src]

Exit the game. Once this function is called, it cannot be cancelled. This does not confirm with Game::can_shutdown.

pub fn window_size(&self) -> (u32, u32)[src]

Get the width and height of the window, excluding the menu bar and borders. This is the renderable surface.

This method is short for window().inner_size()

pub fn new_gui_element(
    &mut self,
    dimensions: (i32, i32, u32, u32)
) -> GuiElementBuilder
[src]

Create a new GUI element. The element will be placed at dimensions.0 / dimensions.1 from the bottom-left of the window, with a size of dimensions.2 x dimensions.3 scaling towards the top-right. The element will ignore window size, it is up to the developer to make sure elements are rendered inside of the window.

The returned builder can either be turned into a GuiElementTextureBuilder by calling .with_texture(path), or into a GuiElementCanvasBuilder by calling .with_canvas(color). See the respective structs for more options.

The returned GuiElement most be stored somewhere. When the GuiElement gets dropped, it will be removed from the screen.

Example

let font = state.load_font("Roboto.ttf").unwrap(); // load the font. Make sure to store this somewhere.
let text: GuiElement = state
    .new_gui_element((100, 100, 300, 80)) // x, y, width, height of the element
    .with_canvas([255, 255, 255, 255]) // Turn this into a white rectangle
    .with_text(&font, 32, "Hello world".into(), [0, 0, 0, 255]) // with a black text
    .with_border(3, [0, 0, 0, 255]) // and a black border
    .build()
    .unwrap();

pub fn new_triangle_model(&mut self) -> ModelBuilder[src]

Create a new triangle at the origin of the world.

See ModelHandle for information on how to move, rotate and clone the triangle.

Note: you must store the handle somewhere. When the handle is dropped, the rectangle is removed from your world and resources are unloaded.

Example

let triangle: ModelHandle = game_state.new_triangle_model()
    .build()
    .unwrap();

pub fn new_rectangle_model(&mut self) -> ModelBuilder[src]

Create a new rectangle at the origin of the world. This can be useful to render simple textures in the world.

See ModelHandle for information on how to move, rotate and clone the rectangle.

Note: you must store the handle somewhere. When the handle is dropped, the rectangle is removed from your world and resources are unloaded.

Example

let rust_logo: ModelHandle = game_state.new_rectangle_model()
    .with_texture_from_file("assets/rust_logo.png")
    .build()
    .unwrap();

pub fn new_obj_model<'a>(&'a mut self, path: &'a str) -> ModelBuilder<'a>[src]

Load a model from the given path and place it at the origin of the world. See ModelHandle for information on how to move, rotate and clone the model.

This method is only available when the format-obj feature is enabled.

pub fn new_fbx_model<'a>(&'a mut self, path: &'a str) -> ModelBuilder<'a>[src]

Load a model from the given path and place it at the origin of the world. See ModelHandle for information on how to move, rotate and clone the model.

This method is only available when the format-fbx feature is enabled.

Auto Trait Implementations

impl !RefUnwindSafe for GameState

impl !Send for GameState

impl !Sync for GameState

impl Unpin for GameState

impl !UnwindSafe for GameState

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Content for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SafeBorrow<T> for T[src]

impl<T> SetParameter for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.