Struct amethyst::Application[][src]

pub struct Application<'a, T> { /* fields omitted */ }

An Application is the root object of the game engine. It binds the OS event loop, state machines, timers and other core components in a central place.

Since Application functions as the root of the game, Amethyst does not need to use any global variables. Within this object is everything that your game needs to run.

Logging

Amethyst performs logging internally using the log crate. By default, Application will initialize a global logger that simply sends logs to the console. You can take advantage of this and use the logging macros in log once you've created your Application instance:

extern crate amethyst;
#[macro_use]
extern crate log;

use amethyst::prelude::*;
use amethyst::core::transform::{Parent, Transform};
use amethyst::ecs::prelude::System;

struct NullState;
impl State<()> for NullState {}

fn main() -> amethyst::Result<()> {
    // Build the application instance to initialize the default logger.
    let mut game = Application::build("assets/", NullState)?
        .build(())?;

    // Now logging can be performed as normal.
    info!("Using the default logger provided by amethyst");
    warn!("Uh-oh, something went wrong!");

    Ok(())
}

You can also setup your own logging system. Simply intialize any global logger that supports log, and it will be used instead of the default logger:

extern crate amethyst;
#[macro_use]
extern crate log;
extern crate env_logger;

use amethyst::prelude::*;
use amethyst::core::transform::{Parent, Transform};
use amethyst::ecs::prelude::System;

struct NullState;
impl State<()> for NullState {}

fn main() -> amethyst::Result<()> {
    // Initialize your custom logger (using env_logger in this case) before creating the
    // `Application` instance.
    env_logger::init();

    // The default logger will be automatically disabled and any logging amethyst does
    // will go through your custom logger.
    let mut game = Application::build("assets/", NullState)?
        .build(())?;

    Ok(())
}

Methods

impl<'a, T> Application<'a, T>
[src]

Creates a new Application with the given initial game state. This will create and allocate all the needed resources for the event loop of the game engine. It is a shortcut for convenience if you need more control over how the engine is configured you should be using build instead.

Parameters

  • path: The default path for asset loading.

  • initial_state: The initial State handler of your game See State for more information on what this is.

Returns

Returns a Result type wrapping the Application type. See errors for a full list of possible errors that can happen in the creation of a Application object.

Type Parameters

  • P: The path type for your standard asset path.

  • S: A type that implements the State trait. e.g. Your initial game logic.

Lifetimes

  • a: The lifetime of the State objects.
  • b: This lifetime is inherited from specs and shred, it is the minimum lifetime of the systems used by Application

Errors

Application will return an error if the internal thread pool fails to initialize correctly because of systems resource limitations

Examples

use amethyst::prelude::*;

struct NullState;
impl State<()> for NullState {}

let mut game = Application::new("assets/", NullState, ()).expect("Failed to initialize");
game.run();

Creates a new ApplicationBuilder with the given initial game state.

This is identical in function to ApplicationBuilder::new.

Run the gameloop until the game state indicates that the game is no longer running. This is done via the State returning Trans::Quit or Trans::Pop on the last state in from the stack. See full documentation on this in State documentation.

Examples

See the example supplied in the new method.

Trait Implementations

impl<'a, T> Debug for Application<'a, T> where
    T: Debug
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'a, T> !Send for Application<'a, T>

impl<'a, T> !Sync for Application<'a, T>