Skip to main content

Scene

Namespace: MonineEngine.Core

The root of the hierarchy, containing all entities, alongside draw information.

public class Scene : System.IDisposable

Inheritance ObjectScene
Implements IDisposable
Attributes NullableContextAttribute, NullableAttribute

Properties

Name

Gets the name of the Scene.

public string Name { get; }

Property Value

String

BackgroundColor

Gets or sets the background colour of the Scene.

public Color BackgroundColor { get; set; }

Property Value

Color

Content

Gets the used for loading scene-specific assets.

public ContentManager Content { get; private set; }

Property Value

ContentManager

Remarks:

Assets loaded through this will be automatically unloaded when the Scene unloads.

Entities

Gets the current entities in the Scene. Cannot be set.

public List<Entity> Entities { get; }

Property Value

List<Entity>

Camera

Gets the Camera2D of the current Scene.

public Camera2D Camera { get; private set; }

Property Value

Camera2D

Constructors

Scene(String, Camera2D)

Constructs a new Scene with the given name.

public Scene(string name, Camera2D camera)

Parameters

name String
The name of the new Scene.

camera Camera2D
The camera of the new Scene.

Remarks:

Unless you are trying to purposely create a dynamic Scene, it is not recommended to use a constructor. Instead, create a class that inherits Scene, and sets up children and settings in Scene.Initialize().

Methods

CreateEntity(String)

Creates a new Entity, places it into the scene, and returns it.

public Entity CreateEntity(string name)

Parameters

name String
The name of the new Entity to add.

Returns

Entity
The Entity that was just created.

AddEntity(Entity)

Takes the given Entity and adds it to the Scene.

public void AddEntity(Entity entity)

Parameters

entity Entity
The new Entity to add.

Find(String)

Searches for an Entity in the Scene with the given name, and returns it.

public Entity Find(string name)

Parameters

name String
The name of the Entity to find.

Returns

Entity
If an Entity with the given name was found, the entity; otherwise, null.

Remarks:

This method does a deep-search of all Entities within the Scene to find the Entity. Calling this repeatedly will impact performance, especially with large Entity counts.

TryFind(String, Entity&)

Tries to find the Entity in the Scene with the given name, and returns a bool based on if the search was successful or not.

public bool TryFind(string name, Entity& entity)

Parameters

name String
The name of the Entity to find.

entity Entity&
If the Entity was found, contains the found Entity; otherwise, contains null.

Returns

Boolean
If an Entity with the given name was found, true; otherwise, false.

Remarks:

This method does a deep-search of all Entities within the Scene to find the Entity. Calling this repeatedly will impact performance, especially with large Entity counts.

Find(Guid)

Searches for an Entity in the Scene with the given GUID, and returns it.

public Entity Find(Guid guid)

Parameters

guid Guid
The GUID of the Entity to find.

Returns

Entity
If an Entity with the given GUID was found, the entity; otherwise, null.

Remarks:

This method does a deep-search of all Entities within the Scene to find the Entity. Calling this repeatedly will impact performance, especially with large Entity counts.

TryFind(Guid, Entity&)

Tries to find the Entity in the Scene with the given GUID, and returns a bool based on if the search was successful or not.

public bool TryFind(Guid guid, Entity& entity)

Parameters

guid Guid
The GUID of the Entity to find.

entity Entity&
If the Entity was found, contains the found entity; otherwise, contains null.

Returns

Boolean
If an Entity with the given name was found, true; otherwise, false.

Remarks:

This method does a deep-search of all Entities within the Scene to find the Entity. Calling this repeatedly will impact performance, especially with large Entity counts.

DestroyEntity(Entity)

Destroys an Entity from the Scene.

public bool DestroyEntity(Entity entity)

Parameters

entity Entity
The Entity to remove.

Returns

Boolean
If the given Entity was successfully removed, true; otherwise, false.

DestroyEntity(Guid)

Destroys an Entity with the given GUID from the Scene.

public bool DestroyEntity(Guid guid)

Parameters

guid Guid
The GUID of the Entity to remove.

Returns

Boolean
If the given Entity was successfully removed, true; otherwise, false.

Initialize()

Called when the Scene gets loaded by SceneManager. Should be used to set up children and the settings of the Scene.

public void Initialize()

Remarks:

Can be overriden for custom logic on scene initialization. When overriden, remember to call base.Initialize(), or the Scene will not be loaded correctly.

LoadContent()

Override to provide logic for loading Scene content. This includes textures, audio, data, etc.

public void LoadContent()

UnloadContent()

Unloads content currently loaded in the scene.

public void UnloadContent()

Remarks:

If overriden, remember to call base.UnloadContent() within the override.

Update(GameTime)

public void Update(GameTime gameTime)

Parameters

gameTime GameTime

Remarks:

Can be overriden for custom update logic, but overrides MUST call base.Update() at some point in the override.

Draw(GameTime)

Draws all entities currently in the scene. Can be overriden for custom drawing, but overrides MUST call base.Draw() at some point in the override.

public void Draw(GameTime gameTime)

Parameters

gameTime GameTime

Finalize()

protected void Finalize()

Dispose()

Disposes of this scene.

public void Dispose()

Dispose(Boolean)

protected void Dispose(bool disposing)

Parameters

disposing Boolean