[][src]Type Definition amethyst::Application

type Application<'a, T> = CoreApplication<'a, T, StateEvent, StateEventReader>;

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 EmptyState for NullState {}

fn main() -> amethyst::Result<()> {
    amethyst::start_logger(Default::default());

    // 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 EmptyState 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(())
}