Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johanhelsing/bevy_trauma_shake
A Bevy plugin for shaking 2d cameras
https://github.com/johanhelsing/bevy_trauma_shake
2d bevy camera camera-shake game-development
Last synced: about 1 month ago
JSON representation
A Bevy plugin for shaking 2d cameras
- Host: GitHub
- URL: https://github.com/johanhelsing/bevy_trauma_shake
- Owner: johanhelsing
- License: apache-2.0
- Created: 2023-11-17T21:26:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-23T14:36:40.000Z (10 months ago)
- Last Synced: 2024-04-26T06:04:03.552Z (8 months ago)
- Topics: 2d, bevy, camera, camera-shake, game-development
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 8
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# bevy_trauma_shake
[![crates.io](https://img.shields.io/crates/v/bevy_trauma_shake.svg)](https://crates.io/crates/bevy_trauma_shake)
![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)
[![crates.io](https://img.shields.io/crates/d/bevy_trauma_shake.svg)](https://crates.io/crates/bevy_trauma_shake)
[![docs.rs](https://img.shields.io/docsrs/bevy_trauma_shake)](https://docs.rs/bevy_trauma_shake)Add camera shakes to your 2d Bevy game with three lines of code.
## Goals
- Zero configuration required
- Sensible defaults
- Batteries included (default noise)
- Compatible with bevy_pancam## Usage
Add the plugin:
```rust ignore
app.add_plugins(TraumaPlugin);
```Simply add a component to your camera:
```rust ignore
commands.spawn((Camera2dBundle::default(), Shake::default()));
```Make it shake:
```rust ignore
fn shake(mut shake: Query<&mut Shake>, keys: Res>) {
if keys.just_pressed(KeyCode::Space) {
shake.single_mut().add_trauma(0.2);
}
}
```There is also a convenience system param for applying trauma to all `Shake`s:
```rust ignore
fn shake(mut shake: Shakes, keys: Res>) {
if keys.just_pressed(KeyCode::Space) {
shakes.add_trauma(0.2);
}
}
```And an event, if you prefer that:
```rust ignore
fn shake(mut trauma: EventWriter, keys: Res>) {
if keys.just_pressed(KeyCode::Space) {
trauma.send(0.2.into());
}
}
```And even a command:
```rust ignore
fn shake(mut commands: Commands, keys: Res>) {
if keys.just_pressed(KeyCode::Space) {
info!("Adding small trauma");
commands.add_trauma(0.2);
}
}
```Maybe I went a little overboard and I should remove one of those ways, in any case, they can be toggled through the features: `system_param`, `events`, `commands`.
## Optional configuration
Optionally add `ShakeSettings`, if you're not happy with the defaults.
```rust ignore
commands.spawn((
Name::new("Camera"),
Camera2dBundle::default(),
Shake::default(),
ShakeSettings {
amplitude: 200.,
trauma_power: 3.,
decay_per_second: 0.3,
frequency: 4.,
octaves: 2,
},
PanCam::default(),
));
```## Bevy Version Support
The `main` branch targets the latest bevy release.
|bevy|bevy_trauma_shake|
|----|-----------------|
|0.14| 0.3, main |
|0.13| 0.2 |
|0.12| 0.1 |## License
`bevy_trauma_shake` is dual-licensed under either
- MIT License (./LICENSE-MIT or )
- Apache License, Version 2.0 (./LICENSE-APACHE or )at your option.
## Thanks
-
- [`bevy_camera_shake`](https://github.com/Andrewp2/bevy_camera_shake): 2D and 3D shakes and more configuration options. I used this a lot for reference, but I wanted a simpler API.## Contributions
PRs welcome!