Table of Contents

Class DrawableComponent

Namespace
BSGameLib.Game.Components
Assembly
BSGameLib.Game.dll

A Component that draws itself each frame. Override Draw(IGameTime) to draw, and LoadContent() and UnloadContent() to load and release assets.

public abstract class DrawableComponent : Component, IUpdateable, IEquatable<IUpdateable>, IDrawable, IIdentifiable<Guid>, IEquatable<IDrawable>
Inheritance
DrawableComponent
Implements
Derived
Inherited Members

Remarks

Each frame, the game calls BeginDraw(), then Draw(IGameTime), then EndDraw(), for every visible drawable in DrawOrder order.

Constructors

DrawableComponent(IContentManager, IRenderContextFactory)

Creates the component. renderContextFactory is needed only by a component that draws through it; it may be null otherwise.

protected DrawableComponent(IContentManager contentManager, IRenderContextFactory renderContextFactory = null)

Parameters

contentManager IContentManager
renderContextFactory IRenderContextFactory

Exceptions

ArgumentNullException

contentManager is null.

Properties

ContentManager

The content manager this component loads its assets through.

public IContentManager ContentManager { get; }

Property Value

IContentManager

DrawOrder

The order this component is drawn in relative to other drawables. Lower values are drawn first.

public int DrawOrder { get; set; }

Property Value

int

IsVisible

Whether the game draws this component. Set to true by LoadContent().

public bool IsVisible { get; set; }

Property Value

bool

RenderContextFactory

The factory this component issues render calls through. Null when none was given to the constructor.

protected IRenderContextFactory RenderContextFactory { get; }

Property Value

IRenderContextFactory

Methods

BeginDraw()

Called before Draw(IGameTime) each frame. Does nothing here.

public virtual void BeginDraw()

Draw(IGameTime)

Draws the component for this frame.

public abstract void Draw(IGameTime gameTime)

Parameters

gameTime IGameTime

EndDraw()

Called after Draw(IGameTime) each frame. Does nothing here.

public virtual void EndDraw()

Equals(DrawableComponent)

Whether other has the same Id as this component.

protected bool Equals(DrawableComponent other)

Parameters

other DrawableComponent

Returns

bool

Equals(IDrawable)

Whether other has the same Id as this component. False when other is null.

public bool Equals(IDrawable other)

Parameters

other IDrawable

Returns

bool

Equals(object)

Whether obj is a drawable component of the same type with the same Id.

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

Returns a hash code based on Id, consistent with Equals(object).

public override int GetHashCode()

Returns

int

LoadContent()

Makes the component visible and raises Loaded. An override that loads assets should call the base method so that Loaded is raised.

public virtual void LoadContent()

UnloadContent()

Releases the assets that LoadContent() loaded. Does nothing here; an override releases its own.

public virtual void UnloadContent()

Update(IGameTime)

Does nothing by default. Override it to advance the component's state each frame.

public override void Update(IGameTime gameTime)

Parameters

gameTime IGameTime

Events

Loaded

Raised by LoadContent() once the component is loaded.

public event EventHandler Loaded

Event Type

EventHandler

Operators

operator ==(DrawableComponent, Component)

Whether left and right have the same Id. Two nulls are equal.

public static bool operator ==(DrawableComponent left, Component right)

Parameters

left DrawableComponent
right Component

Returns

bool

operator ==(DrawableComponent, DrawableComponent)

Whether left and right have the same Id. Two nulls are equal.

public static bool operator ==(DrawableComponent left, DrawableComponent right)

Parameters

left DrawableComponent
right DrawableComponent

Returns

bool

operator ==(DrawableComponent, IDrawable)

Whether left and right have the same Id. Two nulls are equal.

public static bool operator ==(DrawableComponent left, IDrawable right)

Parameters

left DrawableComponent
right IDrawable

Returns

bool

operator !=(DrawableComponent, Component)

Whether left and right have different Id values.

public static bool operator !=(DrawableComponent left, Component right)

Parameters

left DrawableComponent
right Component

Returns

bool

operator !=(DrawableComponent, DrawableComponent)

Whether left and right have different Id values.

public static bool operator !=(DrawableComponent left, DrawableComponent right)

Parameters

left DrawableComponent
right DrawableComponent

Returns

bool

operator !=(DrawableComponent, IDrawable)

Whether left and right have different Id values.

public static bool operator !=(DrawableComponent left, IDrawable right)

Parameters

left DrawableComponent
right IDrawable

Returns

bool