Scene
Declaration
public class Strawberry.Core.Scene
Represents a game scene that manages entities, viewports, layers, and physics. Acts as a container for all objects and logic within a specific state or level of the game.
Inherits: Strawberry.ReferenceObject
Constructors
Scene
Initializes a new instance of the Scene class.
void Scene(string name, int width, int height)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
System.String |
The name of the scene. |
width |
System.Int32 |
The width of the scene in pixels. |
height |
System.Int32 |
The height of the scene in pixels. |
Properties
GameContext
Gets the game context associated with this scene.
IGameContext GameContext { get }
Entities
Gets the collection of entities currently in the scene.
EntityCollection Entities { get }
Width
Gets or sets the width of the scene in pixels.
int Width { get set }
Height
Gets or sets the height of the scene in pixels.
int Height { get set }
Viewports
Gets or sets the collection of viewports used to render the scene.
ViewportCollection Viewports { get set }
MousePosition
Gets an array of mouse positions, indexed by pointer ID.
Vector2[] MousePosition { get }
DestroyCount
Gets the total number of entities that have been destroyed in the scene.
int DestroyCount { get }
ClearColor
Gets or sets the color used to clear the screen before rendering the scene. If set to transparent, the previous frame's content may remain.
Color ClearColor { get set }
Name
Gets the name of the scene.
string Name { get }
IsInitialized
Gets a value indicating whether the scene has been initialized and has a valid GameContext.
bool IsInitialized { get }
Layers
Gets or sets the collection of rendering layers used to order draw calls.
LayerCollection Layers { get set }
PhysicsWorld
Gets or sets the Aether.Physics2D world used for physics simulation in this scene.
World PhysicsWorld { get set }
PhysicsEnabled
Gets a value indicating whether the physics simulation is enabled for this scene.
bool PhysicsEnabled { get }
PixelPerMeter
Gets or sets the pixel-to-meter conversion ratio used by the physics simulation.
float PixelPerMeter { get set }
Bounds
Gets the bounding rectangle of the scene, defined by its width and height.
Rectangle Bounds { get }
Methods
Initialize virtual
Initializes the scene with the specified game context and creates a default viewport if none exist.
void Initialize(IGameContext context)
Parameters:
| Name | Type | Description |
|---|---|---|
context |
Strawberry.Core.IGameContext |
The game context to associate with this scene. |
OnInitInstances virtual
Raises the InitInstances event.
void OnInitInstances()
OnFinish virtual
Raises the Finish event.
void OnFinish()
OnEndUpdate virtual
Calls OnEndUpdate on all active root entities and processes the destruction of entities marked for removal.
void OnEndUpdate()
GetMousePositionOnViewport
Calculates the position of the mouse pointer relative to a specific viewport's scene coordinates.
Vector2 GetMousePositionOnViewport(int viewPortIndex, int pointerIndex)
Parameters:
| Name | Type | Description |
|---|---|---|
viewPortIndex |
System.Int32 |
The index of the viewport in the Viewports collection. |
pointerIndex |
System.Int32 |
The index of the pointer (e.g., for multi-touch). |
Returns: The translated mouse position in scene-space coordinates.
OnBeginUpdate virtual
Calls OnBeginUpdate on all active root entities.
void OnBeginUpdate()
OnUpdate virtual
Updates the scene by raising the Update event, updating layers, and calling OnUpdate on all active root entities.
void OnUpdate()
OnFixedUpdate virtual
Performs fixed-time step updates for entities and steps the physics world if enabled.
void OnFixedUpdate()
DestroyEntity
Destroys all entities of a specific type. Note: This method is currently not implemented.
void DestroyEntity(Type t)
Parameters:
| Name | Type | Description |
|---|---|---|
t |
System.Type |
The type of entity to destroy. |
EntityCount
int EntityCount(string tag)
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
System.String |
DestroyEntity
Destroys all entities that have the specified tag.
void DestroyEntity(string tag)
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
System.String |
The tag used to identify entities to destroy. |
AddEntity virtual
Adds an entity to the scene. If the scene is already initialized, the entity is enabled immediately.
void AddEntity(Entity entity)
Parameters:
| Name | Type | Description |
|---|---|---|
entity |
Strawberry.Core.Entity |
The entity to add. |
FindEntities
Entity[] FindEntities(string tag)
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
System.String |
DestroyEntity
Marks the specified entity for destruction.
void DestroyEntity(Entity entity)
Parameters:
| Name | Type | Description |
|---|---|---|
entity |
Strawberry.Core.Entity |
The entity to destroy. |
DoRender virtual
Performs custom rendering logic. Override this to add rendering outside of the standard entity rendering.
void DoRender()
DoGuiRender virtual
Performs custom GUI rendering logic. Override this to add GUI rendering.
void DoGuiRender()
OnRender virtual
Renders the scene by iterating through viewports and drawing active entities and layers.
void OnRender()
OnBeginRender
Clears the rendering surface using the ClearColor if it is not transparent.
bool OnBeginRender()
Returns: true if the screen was cleared; false if the clear color was transparent.
AddLayer
Adds a rendering layer to the scene. If the layer belongs to another scene, it is removed from that scene first.
void AddLayer(string key, Layer layer)
Parameters:
| Name | Type | Description |
|---|---|---|
key |
System.String |
The unique key identifying the layer. |
layer |
Strawberry.Graphics.Layers.Layer |
The layer to add. |
RemoveLayer virtual
Removes the rendering layer with the specified key.
void RemoveLayer(string key)
Parameters:
| Name | Type | Description |
|---|---|---|
key |
System.String |
The key of the layer to remove. |
RemoveLayer virtual
Removes the specified rendering layer from the scene.
string RemoveLayer(Layer layer)
Parameters:
| Name | Type | Description |
|---|---|---|
layer |
Strawberry.Graphics.Layers.Layer |
The layer to remove. |
Returns: The key associated with the removed layer, or null if the layer was not found.
EnablePhysics virtual
Enables the physics simulation with the specified gravity vector.
void EnablePhysics(Vector2 gravity)
Parameters:
| Name | Type | Description |
|---|---|---|
gravity |
Strawberry.Math.Vector2 |
The gravity vector applied to the physics world. |
Events
Update
Occurs when the scene is updated.
event EventHandler Update
InitInstances
Occurs when instances within the scene are being initialized.
event EventHandler InitInstances
Finish
Occurs when the scene is finishing.
event EventHandler Finish