Table of Contents

Class GameElement

Namespace
LibGFX.Core
Assembly
LibGFX.dll

Represents a game element

public abstract class GameElement : IIdentifier, IPropertyTable, ISerialization
Inheritance
GameElement
Implements
Derived
Inherited Members

Constructors

GameElement()

Creates a new game element

protected GameElement()

Properties

AABB

The axis-aligned bounding box (AABB) of the game element.

public AABB AABB { get; set; }

Property Value

AABB

Behaviors

The behaviors of the game element

public List<IGameBehavior> Behaviors { get; set; }

Property Value

List<IGameBehavior>

CastShadows

Determines if the game element casts shadows

public virtual bool CastShadows { get; set; }

Property Value

bool

Children

The children of the game element

public IReadOnlyList<GameElement> Children { get; }

Property Value

IReadOnlyList<GameElement>

Enabled

Determines if the game element is enabled

public virtual bool Enabled { get; set; }

Property Value

bool

HasTransparency

Determines if the game element has transparency.

public abstract bool HasTransparency { get; }

Property Value

bool

ID

The ID of the game element

public Guid ID { get; set; }

Property Value

Guid

Name

The name of the game element

public string Name { get; set; }

Property Value

string

Parent

The parent of the game element

public GameElement Parent { get; set; }

Property Value

GameElement

Properties

Gets a collection of custom properties associated with the current instance.

public Dictionary<string, object> Properties { get; }

Property Value

Dictionary<string, object>

Remarks

Use this dictionary to store and retrieve additional metadata or user-defined values related to the instance. Property names are case-sensitive. Modifying the collection affects only the current instance.

Tags

A set of tags associated with the game element, used for categorization or filtering.

public HashSet<string> Tags { get; }

Property Value

HashSet<string>

Transform

The transform of the game element

public virtual Transform Transform { get; set; }

Property Value

Transform

Visible

Determines if the game element is visible

public virtual bool Visible { get; set; }

Property Value

bool

WorldAABB

Gets the world axis-aligned bounding box (AABB) of the game element.

public AABB WorldAABB { get; }

Property Value

AABB

Methods

AddBehavior<T>(T)

Adds a behavior to the game element

public T AddBehavior<T>(T behavior) where T : IGameBehavior

Parameters

behavior T

Returns

T

Type Parameters

T

AddChild(GameElement)

Adds a child to the game element

public void AddChild(GameElement child)

Parameters

child GameElement

AddTag(string)

Adds a tag to the game element.

public void AddTag(string tag)

Parameters

tag string

Collide(Collision)

Collides the game element

public virtual void Collide(Collision collision)

Parameters

collision Collision

ComputeAABB()

Computes the axis-aligned bounding box (AABB) of the game element.

public abstract void ComputeAABB()

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Deserializes the JSON representation into the current object and its hierarchy.

public virtual void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)

Parameters

obj JObject
serializationContext SerializationContext
callback Func<JObject, bool>

Exceptions

Exception

Dispose(BaseScene, IRenderDevice)

Disposes the game element

public virtual void Dispose(BaseScene scene, IRenderDevice renderer)

Parameters

scene BaseScene
renderer IRenderDevice

FindChild<T>()

Searches the immediate child elements and returns the first child of the specified type.

public T FindChild<T>() where T : GameElement

Returns

T

The first child element of type T if found; otherwise, null.

Type Parameters

T

The type of child element to search for. Must derive from GameElement.

Remarks

Only immediate children are considered in the search. If multiple children of type T exist, only the first is returned.

FindChild<T>(string)

Searches for a child element of the specified type with the given name.

public T FindChild<T>(string name) where T : GameElement

Parameters

name string

The name of the child element to locate. The comparison is case-sensitive.

Returns

T

The first child element of type T with the specified name, or null if no matching element is found.

Type Parameters

T

The type of child element to search for. Must derive from GameElement.

Remarks

If multiple child elements of type T share the same name, only the first one encountered is returned. The search is limited to immediate children and does not include nested descendants.

FindChildren<T>()

Returns an array containing all child elements of the specified type.

public T[] FindChildren<T>() where T : GameElement

Returns

T[]

An array of elements of type T that are children of this instance. The array is empty if no matching children are found.

Type Parameters

T

The type of child elements to search for. Must derive from GameElement.

FindChildren<T>(string)

Finds all child elements of the specified type that have the given name.

public T[] FindChildren<T>(string name) where T : GameElement

Parameters

name string

The name of the child elements to find. The comparison is case-sensitive.

Returns

T[]

An array containing all child elements of type T whose Name property matches the specified name. The array will be empty if no matching elements are found.

Type Parameters

T

The type of child elements to search for. Must derive from GameElement.

GetBehavior<T>()

Gets a behavior from the game element

public T GetBehavior<T>() where T : IGameBehavior

Returns

T

Type Parameters

T

GetMeshes()

Returns the meshes and materials of the game element

public virtual Mesh[]? GetMeshes()

Returns

Mesh[]

GetWorldAABB()

Gets the world axis-aligned bounding box (AABB) of the game element by transforming its local AABB using its world transform.

public AABB GetWorldAABB()

Returns

AABB

GetWorldTransform()

Gets the world transform of the game element by recursively combining its local transform with its parent's world transform.

public Transform GetWorldTransform()

Returns

Transform

HasTag(string)

Checks if the game element has a specific tag.

public bool HasTag(string tag)

Parameters

tag string

Returns

bool

Init(BaseScene, Viewport, IRenderDevice)

Initializes the game element

public virtual void Init(BaseScene scene, Viewport viewport, IRenderDevice renderer)

Parameters

scene BaseScene
viewport Viewport
renderer IRenderDevice

RemoveTag(string)

Removes a tag from the game element.

public void RemoveTag(string tag)

Parameters

tag string

Render(BaseScene, Viewport, IRenderDevice, Camera)

Renders the game element

public virtual void Render(BaseScene scene, Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

scene BaseScene
viewport Viewport
renderer IRenderDevice
camera Camera

RenderShadow(BaseScene, Viewport, IRenderDevice)

Renders the shadow of the game element

public virtual void RenderShadow(BaseScene scene, Viewport viewport, IRenderDevice renderer)

Parameters

scene BaseScene
viewport Viewport
renderer IRenderDevice

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the current object and its hierarchy into a JSON representation.

public virtual void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
serializationContext SerializationContext

The context that provides serialization settings and state information used during the serialization process.

callback Action<JsonWriter>

Remarks

The returned JSON object includes information about the object's type, identifier, name, transform, visibility, enabled state, shadow casting, parent, tags, axis-aligned bounding boxes, children, and custom properties. Behaviors are not currently serialized and are represented as an empty array.

Update(BaseScene, float)

Updates the game element

public virtual void Update(BaseScene scene, float dt)

Parameters

scene BaseScene
dt float