Table of Contents

Class GameExtensions

Namespace
Stride.CommunityToolkit.Bepu
Assembly
Stride.CommunityToolkit.Bepu.dll

Provides extension methods for the Game class to simplify common game setup tasks for the Bepu Physics engine.

public static class GameExtensions
Inheritance
GameExtensions

Methods

Add2DGround(Game, string?, Vector2?, bool)

Adds a 2D ground entity to the specified game with optional name, size, and collider settings.

public static Entity Add2DGround(this Game game, string? entityName = "Ground", Vector2? size = null, bool includeCollider = true)

Parameters

game Game

The game instance to which the ground entity will be added.

entityName string

The name to assign to the ground entity. If null, a default name is used.

size Vector2?

The size of the ground entity in world units. If null, a default size is applied.

includeCollider bool

Specifies whether a collider should be included with the ground entity. Set to true to add a collider; otherwise, false.

Returns

Entity

The newly created ground entity added to the game.

Remarks

The ground entity is created using a cube primitive model and is suitable for 2D gameplay scenarios. The default size and name are defined by Default2DGroundSize and DefaultGroundName, respectively.

Add3DGround(Game, string?, Vector2?, bool)

Adds a 3D ground entity to the game.

public static Entity Add3DGround(this Game game, string? entityName = "Ground", Vector2? size = null, bool includeCollider = true)

Parameters

game Game

Game instance.

entityName string

Optional entity name; defaults to DefaultGroundName.

size Vector2?

Optional ground size; defaults to Default3DGroundSize.

includeCollider bool

If true, attaches a CompoundCollider.

Returns

Entity

The created ground Entity.

Create2DPrimitive(IGame, Primitive2DModelType, Bepu2DPhysicsOptions?)

Creates a 2D primitive entity and attaches a Bepu physics component as defined by options.

public static Entity Create2DPrimitive(this IGame game, Primitive2DModelType type, Bepu2DPhysicsOptions? options = null)

Parameters

game IGame
type Primitive2DModelType
options Bepu2DPhysicsOptions

Returns

Entity

Create3DPrimitive(IGame, PrimitiveModelType, Bepu3DPhysicsOptions?)

Creates a 3D primitive entity and attaches a Bepu physics component as defined by options.

public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type, Bepu3DPhysicsOptions? options = null)

Parameters

game IGame

The game instance.

type PrimitiveModelType

Which primitive shape to create.

options Bepu3DPhysicsOptions

Options for both the primitive geometry and physics. If null, defaults will be used.

Returns

Entity

The newly created Entity.

SetupBase2DScene(Game)

Sets up a default 2D scene for the game, similar to creating an empty project through the editor.

public static void SetupBase2DScene(this Game game)

Parameters

game Game

SetupBase3DScene(Game)

Sets up a default 3D scene for the game, similar to creating an empty project through the editor.

public static void SetupBase3DScene(this Game game)

Parameters

game Game

The Game instance for which the base 3D scene will be set up.

Remarks

This method performs the following setup operations in sequence:

  1. Adds a default GraphicsCompositor to the game's SceneSystem and applies a clean UI stage.
  2. Adds a camera to the game and sets it up with a MouseLookCamera component.
  3. Adds a directional light to the game scene.
  4. Adds ground geometry to the game scene.