#propagation #bevy #transform #spatial #2d #gamedev #game-engine

rantz_spatial2d

A set of 2D spatial utilities for Bevy, including handling transform propagation

15 releases (3 major breaking)

3.1.2 Jul 20, 2024
3.1.1 Jul 9, 2024
2.0.0 Jul 5, 2024
1.0.0 Jul 5, 2024
0.2.3 May 23, 2024

#228 in Game dev

Download history 29/week @ 2024-06-26 435/week @ 2024-07-03 191/week @ 2024-07-10 122/week @ 2024-07-17 13/week @ 2024-07-24 1/week @ 2024-07-31 45/week @ 2024-09-11 29/week @ 2024-09-18 29/week @ 2024-09-25 9/week @ 2024-10-02

69 downloads per month
Used in 2 crates

MIT/Apache

160KB
4.5K SLoC

rantz_spatial2d

A 2d transform system for the Bevy game engine that supports Transform propagation controls.

Core Types

Position2D

The Position2D struct represents a 2D point in space. It has two fields: x and y, representing the Cartesian coordinates of the point.

Rotation2D

The Rotation2D struct represents a 2D rotation. It can be used with either radians or degrees.

Scale2D

The Scale2D struct represents a 2D scale. It has two fields: x and y, representing the scale factors for the x and y axes respectively.

SpatialBundle2D

The SpatialBundle2D struct represents the spatial state of a transform in 2D. It contains a Position2D, Rotation2D, and Scale2D. It provides a convenient way to store and manipulate the spatial state of your game objects.

When you add a SpatialBundle2D to an entity, it will also automatically add a SpatialBundle, making it easy to use the spatial 2D system with Bevy's built-in transform system.

DrawOrder

The DrawOrder struct is used to specify the draw layering of entities in your game. It is a wrapper over an f32, with higher values drawing above lower values.

propagation Types

The following enums are used to control how the spatial components of an entity are propagated to its children.

PositionPropagation

The PositionPropagation enum has two variants:

Relative: **[Default]**The position of a child entity is relative to its parent's position.

Absolute: The position of a child entity is absolute and does not take into account its parent's position.

RotationPropagation

The RotationPropagation enum has two variants:

Relative: **[Default]**The rotation of a child entity is relative to its parent's rotation.

Absolute: The rotation of a child entity is absolute and does not take into account its parent's rotation. By default, both PositionPropagation and RotationPropagation are set to Relative.

ScalePropagation

The ScalePropagation enum has two variants:

Relative: **[Default]**The rotation of a child entity is relative to its parent's rotation.

Absolute: The rotation of a child entity is absolute and does not take into account its parent's rotation.

Compasses

In addition to the above, and not included in the SpatialBundle2D are Compass, CompassRose, and CompassHalfwinds. It is very common in 2D games to need to know the compass direction a given entity is facing in order to choose which sprite to draw. These enums can be included as a component on anything with a Rotation2D, and as part of transform propagation, there values will be updated to match the objects rotation.

Feature Flags

  • serde - Adds impls for serde:Serialize and serde:Deserialize

Usage

Add the crate to your Cargo.toml

If using bevy, add SpatialPlugin2D to your app.

Dependencies

~42–78MB
~1.5M SLoC