Table of Contents

Class GameObject

Namespace
MonoEight.Core
Assembly
MonoEight.Template.dll

Represents the base gameobject in the game world. Acts as a container for Components and handles their lifecycle.

public class GameObject : IDisposable
Inheritance
GameObject
Implements
Derived
Inherited Members

Properties

Canvas

Gets the UI Canvas associated with the current scene.

public Canvas? Canvas { get; }

Property Value

Canvas

IsActive

Gets or sets whether the object is active. If false, the object (and its components) will skip Update() and Draw(SpriteBatch).

public bool IsActive { get; set; }

Property Value

bool

Position

Gets or sets the world space position of the object.

public Vector2 Position { get; set; }

Property Value

Vector2

Scene

Gets the Scene that owns this object.

public Scene? Scene { get; }

Property Value

Scene

ShouldDestroy

Gets whether the object is marked for destruction at the end of the frame.

public bool ShouldDestroy { get; }

Property Value

bool

Methods

AddComponent(Component)

Attaches a new Component to this object.

public void AddComponent(Component component)

Parameters

component Component

The component instance to add.

Remarks

Side Effect: If the component is a Collider, it is automatically registered with the Scene's physics system.

AddComponent<T>()

Creates a new component of type T, attaches it to the object, and returns it.

public T AddComponent<T>() where T : Component, new()

Returns

T

Type Parameters

T

Destroy()

Marks the object to be removed from the scene at the end of the current update cycle.

public void Destroy()

Dispose()

Disposes all attached components and clears references.

public virtual void Dispose()

Draw(SpriteBatch)

Called once per frame to render the object.

protected virtual void Draw(SpriteBatch spriteBatch)

Parameters

spriteBatch SpriteBatch

Microsoft.Xna.Framework.Graphics.SpriteBatch

GetComponent<T>()

Retrieves the first component of the given type.

public T? GetComponent<T>() where T : Component

Returns

T

The component instance, or null if not found.

Type Parameters

T

The type of component to find.

GetComponents<T>()

Retrieves all components of the given type.

public T[] GetComponents<T>() where T : Component

Returns

T[]

An array containing all matching components.

Type Parameters

T

The type of components to find.

Initialize()

Called when the object is initialized. Override to set up initial state.

protected virtual void Initialize()

InternalDraw(SpriteBatch)

public void InternalDraw(SpriteBatch spriteBatch)

Parameters

spriteBatch SpriteBatch

InternalInitialize()

public void InternalInitialize()

InternalLoadContent()

public void InternalLoadContent()

InternalUpdate()

public void InternalUpdate()

LoadContent()

Called when content needs to be loaded. Override to load assets.

protected virtual void LoadContent()

Update()

Called once per frame to update logic.

protected virtual void Update()