Full-screen flashes and camera shake triggered by gameplay (explosions, hits).
More...
|
| | ScreenEffects (EffectSettings settings={}, std::uint64_t seed=0) noexcept |
| | Creates the effects, with nothing showing.
|
| |
| void | set_settings (EffectSettings settings) noexcept |
| | Changes the player's choice; turning an effect off stops it at once.
|
| |
| EffectSettings | settings () const noexcept |
| | The player's choice.
|
| |
| bool | flash (Color color, float seconds) noexcept |
| | Starts a full-screen flash that fades out, replacing the current one.
|
| |
| bool | shake (float strength, float seconds) noexcept |
| | Starts a shake that calms down, unless a stronger one is running.
|
| |
| void | update (float seconds) noexcept |
| | Moves the effects forward in time.
|
| |
| Color | flash_color () const noexcept |
| | Color drawn over the screen this frame.
|
| |
| Color | tint (Color background) const noexcept |
| | Blends the flash over a color, for games that flash their background.
|
| |
| std::optional< Sprite > | overlay (Vec2 screen) const noexcept |
| | Full-screen sprite of the flash, to draw over the scene.
|
| |
| Vec2 | offset () const noexcept |
| | Offset to add to the camera this frame.
|
| |
Full-screen flashes and camera shake triggered by gameplay (explosions, hits).
Gameplay asks for a flash or a shake; each frame the game calls update(), then draws overlay() over the scene, or blends the flash into its clear color with tint(), and moves its camera by offset() (Camera::set_shake()). With EffectSettings::flashes or EffectSettings::shake off, the requests are ignored and nothing is drawn or moved. Even when flashes are on, at most max_flashes_per_second start in any second, the limit of WCAG 2.3.1 for content that flashes.
effects.
shake(8.0F, 0.3F);
...
effects.update(frame_seconds);
renderer.begin_frame(effects.tint(background));
camera.set_shake(effects.offset());
renderer.set_camera(camera);
... draw the scene ...
renderer.set_camera(std::nullopt);
if (
const auto flash = effects.overlay(screen_size)) { renderer.draw(*
flash); }
Full-screen flashes and camera shake triggered by gameplay (explosions, hits).
Definition screen_effects.hpp:65
bool flash(Color color, float seconds) noexcept
Starts a full-screen flash that fades out, replacing the current one.
EffectSettings settings() const noexcept
The player's choice.
constexpr Color rgb(std::uint32_t hex, float alpha=1.0F) noexcept
Color from its hexadecimal sRGB code, as design tools and palettes give it.
Definition color.hpp:25
bool shake
Whether the screen shakes.
Definition screen_effects.hpp:28