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
contentManagerIContentManagerrenderContextFactoryIRenderContextFactory
Exceptions
- ArgumentNullException
contentManageris null.
Properties
ContentManager
The content manager this component loads its assets through.
public IContentManager ContentManager { get; }
Property Value
DrawOrder
The order this component is drawn in relative to other drawables. Lower values are drawn first.
public int DrawOrder { get; set; }
Property Value
IsVisible
Whether the game draws this component. Set to true by LoadContent().
public bool IsVisible { get; set; }
Property Value
RenderContextFactory
The factory this component issues render calls through. Null when none was given to the constructor.
protected IRenderContextFactory RenderContextFactory { get; }
Property Value
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
gameTimeIGameTime
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
otherDrawableComponent
Returns
Equals(IDrawable)
Whether other has the same Id as this component. False when other is null.
public bool Equals(IDrawable other)
Parameters
otherIDrawable
Returns
Equals(object)
Whether obj is a drawable component of the same type with the same Id.
public override bool Equals(object obj)
Parameters
objobject
Returns
GetHashCode()
Returns a hash code based on Id, consistent with Equals(object).
public override int GetHashCode()
Returns
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
gameTimeIGameTime
Events
Loaded
Raised by LoadContent() once the component is loaded.
public event EventHandler Loaded
Event Type
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
leftDrawableComponentrightComponent
Returns
operator ==(DrawableComponent, DrawableComponent)
Whether left and right have the same Id. Two nulls are equal.
public static bool operator ==(DrawableComponent left, DrawableComponent right)
Parameters
leftDrawableComponentrightDrawableComponent
Returns
operator ==(DrawableComponent, IDrawable)
Whether left and right have the same Id. Two nulls are equal.
public static bool operator ==(DrawableComponent left, IDrawable right)
Parameters
leftDrawableComponentrightIDrawable
Returns
operator !=(DrawableComponent, Component)
Whether left and right have different Id values.
public static bool operator !=(DrawableComponent left, Component right)
Parameters
leftDrawableComponentrightComponent
Returns
operator !=(DrawableComponent, DrawableComponent)
Whether left and right have different Id values.
public static bool operator !=(DrawableComponent left, DrawableComponent right)
Parameters
leftDrawableComponentrightDrawableComponent
Returns
operator !=(DrawableComponent, IDrawable)
Whether left and right have different Id values.
public static bool operator !=(DrawableComponent left, IDrawable right)
Parameters
leftDrawableComponentrightIDrawable