Class GameExtensions
Provides extension methods for Game and IGame to simplify common scene setup and primitive creation tasks with Bepu physics.
public static class GameExtensions
- Inheritance
-
GameExtensions
Methods
Add2DGround(Game, Bepu2DPhysicsOptions?)
Adds a 2D ground entity to the game using a cube primitive and Bepu static physics.
public static Entity Add2DGround(this Game game, Bepu2DPhysicsOptions? options = null)
Parameters
gameGameThe game instance to which the ground entity will be added.
optionsBepu2DPhysicsOptionsOptional 2D physics options used to configure the ground. When provided, Size is mapped to X/Y while Z uses Default2DGroundSize, and Position defaults to Default2DGroundPosition.
Returns
Remarks
The resulting entity is created through 3D primitive generation and uses a StaticComponent with a CompoundCollider when no physics component is supplied in options.
Add3DGround(Game, Bepu3DPhysicsOptions?)
Adds a 3D ground entity to the game using a plane primitive and Bepu static physics.
public static Entity Add3DGround(this Game game, Bepu3DPhysicsOptions? options = null)
Parameters
gameGameThe game instance to which the ground entity will be added.
optionsBepu3DPhysicsOptionsOptional 3D physics options used to configure the ground. If
null, defaults will be used.
Returns
Remarks
Unless Component is set explicitly, the ground gets a StaticComponent with a CompoundCollider - including when other options such as Size are provided. If EntityName is not provided, DefaultGroundName is used.
AddGrabber(Game)
Puts a GrabberScript on the camera entity, so the left mouse button picks up any dynamic body, carries it on the end of the camera ray and throws it on release.
public static GrabberScript AddGrabber(this Game game)
Parameters
gameGameThe game whose camera entity gets the grabber.
Returns
- GrabberScript
The grabber, for tuning its reach, force and keys.
Remarks
The script is also a Game Studio component, under Physics, for a project that would rather place it on the camera entity in the editor.
Create2DPrimitive(IGame, Primitive2DModelType)
Creates a 2D primitive entity with a matching Bepu collider, using the default options.
public static Entity Create2DPrimitive(this IGame game, Primitive2DModelType type)
Parameters
gameIGameThe game instance.
typePrimitive2DModelTypeThe type of 2D primitive shape to create.
Returns
Remarks
Exists so that game.Create2DPrimitive(type) resolves here rather than to the physics-free
overload in Stride.CommunityToolkit.Engine, which has the same shape and is in scope whenever this
package is. Both are applicable to that call; C# prefers the candidate that needs no default argument
substituted, so this exact-arity overload wins, and F# applies the same preference. VB does not, so VB
callers pass the options explicitly. Passing a Bepu2DPhysicsOptions reaches the overload
below; passing a Primitive2DEntityOptions reaches the physics-free one.
Two things keep this working: a literal null for the options is still ambiguous, so use a typed
null as the forwarding call here does; and the core method must not grow an exact-arity overload of its
own, or the tie returns. This shadowing is a bridge until physics is selected once at setup, at which
point these overloads go.
Create2DPrimitive(IGame, Primitive2DModelType, Bepu2DPhysicsOptions?)
Creates a 2D primitive entity and attaches Bepu 2D physics as defined by options.
public static Entity Create2DPrimitive(this IGame game, Primitive2DModelType type, Bepu2DPhysicsOptions? options = null)
Parameters
gameIGameThe game instance.
typePrimitive2DModelTypeThe type of 2D primitive shape to create.
optionsBepu2DPhysicsOptionsOptions for both the primitive geometry and physics. If
null, defaults will be used.
Returns
Create3DPrimitive(IGame, PrimitiveModelType)
Creates a 3D primitive entity with a matching Bepu collider, using the default options.
public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type)
Parameters
gameIGameThe game instance.
typePrimitiveModelTypeThe type of 3D primitive shape to create.
Returns
Remarks
Exists so that game.Create3DPrimitive(type) resolves here rather than to the physics-free
overload in Stride.CommunityToolkit.Engine, which has the same shape and is in scope whenever this
package is. Both are applicable to that call; C# prefers the candidate that needs no default argument
substituted, so this exact-arity overload wins, and F# applies the same preference. VB does not, so VB
callers pass the options explicitly. Passing a Bepu3DPhysicsOptions reaches the overload
below; passing a Primitive3DEntityOptions reaches the physics-free one.
Two things keep this working: a literal null for the options is still ambiguous, so use a typed
null as the forwarding call here does; and the core method must not grow an exact-arity overload of its
own, or the tie returns. This shadowing is a bridge until physics is selected once at setup, at which
point these overloads go.
Create3DPrimitive(IGame, PrimitiveModelType, Bepu3DPhysicsOptions?)
Creates a 3D primitive entity and attaches Bepu 3D physics as defined by options.
public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type, Bepu3DPhysicsOptions? options = null)
Parameters
gameIGameThe game instance.
typePrimitiveModelTypeThe type of 3D primitive shape to create.
optionsBepu3DPhysicsOptionsOptions for both the primitive geometry and physics. If
null, defaults will be used.
Returns
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
gameGameThe game instance to configure with the base 2D scene setup.
Remarks
This method performs the following setup operations in sequence:
- Configures base 2D scene settings.
- Adds a 2D camera controller.
- Adds a 2D ground entity with Bepu physics.
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
gameGameThe game instance to configure with the base 3D scene setup.
Remarks
This method performs the following setup operations in sequence:
- Configures base 3D scene settings.
- Adds a 3D camera controller.
- Adds a 3D ground entity with Bepu physics.