Stars scrolling across the screen in layers, each at its own speed: a parallax background for a side-scrolling shooter.
More...
#include <aegis2d/render/starfield.hpp>
|
| | Starfield (Vec2 area, std::span< const StarLayer > layers=default_star_layers, std::uint64_t seed=1) |
| | Spreads the stars of each layer over an area.
|
| |
| void | update (double seconds) noexcept |
| | Moves time forward.
|
| |
| void | update (core::Duration step) noexcept |
| | Moves time forward by a step, such as one tick of core::MainLoop.
|
| |
| void | draw (IRenderer &renderer, std::int32_t layer=-100) const |
| | Draws every star, from the farthest layer to the nearest.
|
| |
| std::vector< Vec2 > | positions (std::size_t layer) const |
| | Where the stars of a layer are now.
|
| |
| double | elapsed () const noexcept |
| | Time spent since the stars were spread.
|
| |
| std::size_t | layers () const noexcept |
| | Number of layers.
|
| |
| std::size_t | size () const noexcept |
| | Number of stars, every layer counted.
|
| |
| Vec2 | area () const noexcept |
| | Area the stars cover.
|
| |
Stars scrolling across the screen in layers, each at its own speed: a parallax background for a side-scrolling shooter.
The stars are spread from a seed, so the same seed gives the same sky. Their positions are a function of the time spent only (elapsed()): update() adds the time of a frame or a tick, and a star that leaves the screen on one side comes back on the other at the same height. The scroll speed is therefore the same at any frame rate, 30 or 144 frames per second, and whether the time comes in many small steps or few large ones.
...
stars.draw(renderer);
Stars scrolling across the screen in layers, each at its own speed: a parallax background for a side-...
Definition starfield.hpp:54
void update(double seconds) noexcept
Moves time forward.
◆ Starfield()
Spreads the stars of each layer over an area.
- Parameters
-
| area | Width and height of the screen, in logical pixels. |
| layers | Layers, from the farthest (drawn first) to the nearest. |
| seed | Seed of the stars' positions. |
- Exceptions
-
| std::invalid_argument | if a dimension of area is not above 0 and finite, or a layer's size is not above 0 and finite or its speed not finite. |
◆ area()
| Vec2 aegis2d::render::Starfield::area |
( |
| ) |
const |
|
noexcept |
Area the stars cover.
- Returns
- The area given to the constructor.
◆ draw()
| void aegis2d::render::Starfield::draw |
( |
IRenderer & |
renderer, |
|
|
std::int32_t |
layer = -100 |
|
) |
| const |
Draws every star, from the farthest layer to the nearest.
- Parameters
-
| renderer | Renderer in a frame. |
| layer | Drawing layer of the stars, below the game's sprites. |
◆ elapsed()
| double aegis2d::render::Starfield::elapsed |
( |
| ) |
const |
|
noexcept |
Time spent since the stars were spread.
- Returns
- The sum of the times given to update(), in seconds.
◆ layers()
| std::size_t aegis2d::render::Starfield::layers |
( |
| ) |
const |
|
noexcept |
Number of layers.
- Returns
- The layers given to the constructor.
◆ positions()
| std::vector< Vec2 > aegis2d::render::Starfield::positions |
( |
std::size_t |
layer | ) |
const |
Where the stars of a layer are now.
- Parameters
-
| layer | Index of the layer, from the farthest. |
- Returns
- The top-left corner of each star, with x from minus its size to the area's width (a star leaving on the left is still partly visible).
- Exceptions
-
| std::out_of_range | if layer is not below layers(). |
◆ size()
| std::size_t aegis2d::render::Starfield::size |
( |
| ) |
const |
|
noexcept |
Number of stars, every layer counted.
- Returns
- The sum of the layers' counts.
◆ update() [1/2]
Moves time forward by a step, such as one tick of core::MainLoop.
- Parameters
-
◆ update() [2/2]
| void aegis2d::render::Starfield::update |
( |
double |
seconds | ) |
|
|
noexcept |
Moves time forward.
- Parameters
-
| seconds | Time spent, such as the last frame's duration; negative values and NaN count as 0. |
The documentation for this class was generated from the following file: