Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/corrosive-games/bevy-parallax
Parallax background plugin for Bevy
https://github.com/corrosive-games/bevy-parallax
bevy bevy-engine bevy-plugin game-development gamedev parallax parallax-scrolling rust rust-lang
Last synced: about 1 month ago
JSON representation
Parallax background plugin for Bevy
- Host: GitHub
- URL: https://github.com/corrosive-games/bevy-parallax
- Owner: Corrosive-Games
- License: mit
- Created: 2022-03-17T00:03:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-06T00:28:32.000Z (3 months ago)
- Last Synced: 2024-09-22T11:32:03.147Z (about 2 months ago)
- Topics: bevy, bevy-engine, bevy-plugin, game-development, gamedev, parallax, parallax-scrolling, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 12.3 MB
- Stars: 113
- Watchers: 6
- Forks: 17
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bevy-parallax
A parallax plugin for the [Bevy Engine](https://bevyengine.org/). This plugin allows you to easily create scrolling parallax backgrounds for your games.
![cyberpunk](assets/cyberpunk.gif)
![fishy](assets/fishy.gif)
## Usage
```rust,no_run
use bevy::prelude::*;
use bevy_parallax::{
LayerSpeed, LayerData, ParallaxCameraComponent, ParallaxMoveEvent, ParallaxPlugin, ParallaxSystems, CreateParallaxEvent
};fn main() {
let primary_window = Window {
title: "Window Name".to_string(),
resolution: (1280.0, 720.0).into(),
resizable: false,
..default()
};
App::new()
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(primary_window),
..default()
})
// Use nearest filtering so our pixel art renders clear
.set(ImagePlugin::default_nearest()),
)
.add_plugins(ParallaxPlugin)
.add_systems(Startup, initialize_camera_system)
.add_systems(Update, move_camera_system.before(ParallaxSystems))
.run();
}pub fn initialize_camera_system(
mut commands: Commands,
mut create_parallax: EventWriter
) {
let camera = commands
.spawn(Camera2dBundle::default())
.insert(ParallaxCameraComponent::default())
.id();
let event = CreateParallaxEvent {
layers_data: vec![
LayerData {
speed: LayerSpeed::Horizontal(0.9),
path: "cyberpunk_back.png".to_string(),
tile_size: UVec2::new(96, 160),
cols: 1,
rows: 1,
scale: Vec2::splat(4.5),
z: 0.0,
..default()
},
LayerData {
speed: LayerSpeed::Horizontal(0.6),
path: "cyberpunk_middle.png".to_string(),
tile_size: UVec2::new(144, 160),
cols: 1,
rows: 1,
scale: Vec2::splat(4.5),
z: 1.0,
..default()
},
LayerData {
speed: LayerSpeed::Horizontal(0.1),
path: "cyberpunk_front.png".to_string(),
tile_size: UVec2::new(272, 160),
cols: 1,
rows: 1,
scale: Vec2::splat(4.5),
z: 2.0,
..default()
},
],
camera: camera,
};
create_parallax.send(event);
}pub fn move_camera_system(
keyboard_input: Res>,
mut move_event_writer: EventWriter,
camera_query: Query>,
) {
let camera = camera_query.get_single().unwrap();
if keyboard_input.pressed(KeyCode::KeyD) || keyboard_input.pressed(KeyCode::ArrowRight) {
move_event_writer.send(ParallaxMoveEvent {
translation: Vec2::new(3.0, 0.0),
rotation: 0.,
camera: camera,
});
} else if keyboard_input.pressed(KeyCode::KeyA) || keyboard_input.pressed(KeyCode::ArrowLeft) {
move_event_writer.send(ParallaxMoveEvent {
translation: Vec2::new(-3.0, 0.0),
rotation: 0.,
camera: camera,
});
}
}
```## Compatible Bevy versions
Compatibility of `bevy-parallax` versions:
| Bevy version | `bevy-parallax` version |
| :----------- | :---------------------- |
| `0.13` | `0.8` |
| `0.12` | `0.7` |
| `0.11` | `0.5` - `0.6` |
| `0.10` | `0.4` |## Credits
- [Fish World Pack](https://spicylobster.itch.io/fish-world-pack)
- [Warped City 2](https://ansimuz.itch.io/warped-city-2)
- [Mills](https://www.freepik.com/free-vector/flat-wheat-background-with-field_1599667.htm#query=mill%20background%20flat&position=25&from_view=search&track=ais#position=25&query=mill%20background%20flat)