Crate bevy_parallaxation2d

Source
Expand description

§bevy_parallaxation2d

Crate providing simple 2D parallax layers in Bevy.

§In this crate:

§Examples

use bevy::prelude::*;

// Import the `bevy_parallaxation2d` crate
use bevy_parallaxation2d::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, ParallaxPlugin::default()))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    // Spawn parallax camera
    commands
        .spawn(Camera2dBundle::default())
        .insert(ParallaxCamera);

    // Spawn:
    // * Main background that repeats in both directions.
    // * Hills that will default to repeating horizontally.
    // * Foreground at the top of the screen.
    commands.spawn_batch(vec![
        ParallaxLayer {
            image: "main_background.png",
            depth: 80.0.into(),
            flags: ParallaxFlags::REPEAT_X_AXIS | ParallaxFlags::REPEAT_Y_AXIS,
            ..default()
        },
        ParallaxLayer {
            image: "hills_background.png",
            depth: 40.0.into(),
            ..default()
        },
        ParallaxLayer {
            image: "branches_foreground.png",
            depth: (-5.0).into(),
            flags: ParallaxFlags::REPEAT_X_AXIS | ParallaxFlags::OFFSET_CAMERA_TOP,
            ..default()
        },
    ]);
}

Modules§

depth
The depth module provides extra functions and options for creating and managing Depth values used in parallax effects.
prelude
The prelude module exports commonly used types to provide a convenient entry point for users of the bevy_parallaxation2d crate. It includes plugins, components, and bitflags necessary for implementing parallax effects.