C# Class GameEngine.Drawing.DrawableSet

A DrawableSet is a collection of IGameDrawable instances (each called a GameDrawableInstance), organised in a first-tier group of STATES. Whenever a STATE (e.g. Running, Walking) is given to a DrawableSet, it will return a list of all the GameDrawableInstances that were stored under that STATE. This provides a very quick and easy way of being able to retrieve items which are related at one go so that they may be drawn together on the screen. Optionally, a second tier grouping mechanism is given by exposing a GROUP variable in each GameDrawableInstance. This second tier grouping mechanism allows for items related to each other, but not necisseraly stored under the same STATE, to have their values set at one go in a batch operation. GameDrawableInstances are important becuase they allow draw options to be set per Entity Drawable, without effecting the draw state of other Entities using the same drawable item. For this reason, properties such as Visibility, Layer, Rotation, Color and SpriteEffects to use are all stored in a GameDrawableInstance rather than an IGameDrawable item. A very brief diagram showing the overview of this structure can be seen below: GameDrawableSet -----> [ STATE0 ] ------> {GameDrawableInstance1, GameDrawableInstance2, ..., GameDrawableInstanceN} -----> [ STATE1 ] ------> ... -----> ... -----> [ STATEN ] ------> ... Similiarly, the same applies for storing by GROUP. The access times of both these allocations is constant O(1) time due to the use of seperate dictionaries. GameDrawableInstance -------> {IGameDrawable, Visible, Rotation, Color, SpriteEffects, Layer }
Mostrar archivo Open project: MichaelAquilina/Some-2D-RPG Class Usage Examples

Public Methods

Method Description
Add ( string state, IGameDrawable drawable, string group = "" ) : DrawableInstance

Adds the specified IGameDrawable to this DrawableSet under the specified *state*. Optionally, the IGameDrawable being added can also be associated with a *group*. When an IGameDrawable is added to a DrawableSet, it is wrapped around a DrawableInstance class that allows properties about the drawable to be set such as its Color, Rotation, Visibility etc... This DrawableInstance that is created to wrap the IGameDrawable is returned by this method.

AddGroup ( string group ) : bool
AddState ( string state ) : bool
ClearAll ( ) : void

Clears all drawable items from this DrawableSet. After this opereation, this DrawableSet will have no more States or Groups.

GetByGroup ( string group ) : HashSet

Returns all the DrawableInstances associated with the *group* specified in the parameter. If the group does not exist within this DrawableSet, a null value is returned.

GetByState ( string state ) : HashSet

Returns all the DrawableInstances associated with the *state* specified in the parameter. If the group does not exist within this DrawableSet, a null value is returned.

GetGroups ( ) : ICollection

Returns a collection of all *groups* found within this DrawableSet.

GetStates ( ) : ICollection

Returns a collection of all *states* found within this DrawableSet.

IsGroupFinished ( string group, GameTime gameTime ) : bool
IsStateFinished ( string state, GameTime gameTime ) : bool
LoadDrawableSetXml ( DrawableSet drawableSet, string path, Microsoft.Xna.Framework.Content.ContentManager content, double startTimeMS ) : void

Loads a DrawableSet file into a specified DrawableSet object. The method requires the string path to the xml file containing the drawable data and a reference to the ContentManager. An optional Layer value can be specified for the ordering of the drawables in the DrawableSet. Currently only supports loading of Animation objects.

Remove ( DrawableInstance drawableInstance ) : bool

Removes the specified DrawableInstance from this DrawableSet. This will only work if the DrawableInstance belongs to this DrawableSet - it will not work if it belongs to another. Returns a true boolean value if the specified instance was found within this set and removed. If nothing was removed, a false value is returned.

Remove ( IGameDrawable drawable, string state ) : bool

Removes the DrawableInstance of the specified drawable from the specified set of this DrawableSet. Returns a true boolean value specifying if such an instance with the specified was found and removed. If nothing was removed, a false value is returned.

Remove ( DrawableSet drawableSet ) : void

Performs Set negation between this DrawableSet and the DrawabelSet specified in the parameter. While two sets should never share the same DrawableInstance, they may share the same IGameDrawable which would be wrapped by an DrawableInstance. If the DrawableSet specified in the parameter contains IGameDrawables within the same state as this DrawableSet, then associated DrawableInstance's are removed.

RemoveGroup ( string group ) : bool
RemoveState ( string state ) : bool
ResetGroup ( string group, GameTime gameTime ) : void

Asks all IGameDrawables within the specified *group* set to perform a Reset operation. By performing a Reset operation, each GameDrawable should act like it has just been created.

ResetState ( string state, GameTime gameTime ) : void

Asks all IGameDrawables within the specified *state* set to perform a Reset operation.

SetGroupProperty ( string group, string property, object value ) : void

Sets the specified property for all the DrawableInstances in the specified group using C# Reflection. The property to be set should be specified as a case sensitive string and its value should be set with an type that matches the Properties type. If the property specified does not exist in the DrawableInstance class, then an ArgumentException is thrown.

SetStateProperty ( string state, string property, object value ) : void

Sets the specified property for all the DrawableInstances in the specified state using C# Reflection. The property to be set should be specified as a case sensitive string and its value should be set with an type that matches the Properties type. If the property specified does not exist in the DrawableInstance class, then an ArgumentException is thrown.

ToString ( ) : string
Union ( DrawableSet drawableSet ) : void

Performs a Set union operation between this DrawableSet and the DrawableSet specified in the parameter. It is important to note that any IGameDrawables newly created in this DrawableSet are wrapped around a *new* DrawableInstance in order to allow properties to be set independently for each one.

Method Details

Add() public method

Adds the specified IGameDrawable to this DrawableSet under the specified *state*. Optionally, the IGameDrawable being added can also be associated with a *group*. When an IGameDrawable is added to a DrawableSet, it is wrapped around a DrawableInstance class that allows properties about the drawable to be set such as its Color, Rotation, Visibility etc... This DrawableInstance that is created to wrap the IGameDrawable is returned by this method.
public Add ( string state, IGameDrawable drawable, string group = "" ) : DrawableInstance
state string
drawable IGameDrawable
group string
return DrawableInstance

AddGroup() public method

public AddGroup ( string group ) : bool
group string
return bool

AddState() public method

public AddState ( string state ) : bool
state string
return bool

ClearAll() public method

Clears all drawable items from this DrawableSet. After this opereation, this DrawableSet will have no more States or Groups.
public ClearAll ( ) : void
return void

GetByGroup() public method

Returns all the DrawableInstances associated with the *group* specified in the parameter. If the group does not exist within this DrawableSet, a null value is returned.
public GetByGroup ( string group ) : HashSet
group string
return HashSet

GetByState() public method

Returns all the DrawableInstances associated with the *state* specified in the parameter. If the group does not exist within this DrawableSet, a null value is returned.
public GetByState ( string state ) : HashSet
state string
return HashSet

GetGroups() public method

Returns a collection of all *groups* found within this DrawableSet.
public GetGroups ( ) : ICollection
return ICollection

GetStates() public method

Returns a collection of all *states* found within this DrawableSet.
public GetStates ( ) : ICollection
return ICollection

IsGroupFinished() public method

public IsGroupFinished ( string group, GameTime gameTime ) : bool
group string
gameTime Microsoft.Xna.Framework.GameTime
return bool

IsStateFinished() public method

public IsStateFinished ( string state, GameTime gameTime ) : bool
state string
gameTime Microsoft.Xna.Framework.GameTime
return bool

LoadDrawableSetXml() public static method

Loads a DrawableSet file into a specified DrawableSet object. The method requires the string path to the xml file containing the drawable data and a reference to the ContentManager. An optional Layer value can be specified for the ordering of the drawables in the DrawableSet. Currently only supports loading of Animation objects.
public static LoadDrawableSetXml ( DrawableSet drawableSet, string path, Microsoft.Xna.Framework.Content.ContentManager content, double startTimeMS ) : void
drawableSet DrawableSet DrawableSet object to load the animations into.
path string String path to the XML formatted .anim file
content Microsoft.Xna.Framework.Content.ContentManager Reference to the ContentManager instance being used in the application
startTimeMS double
return void

Remove() public method

Removes the specified DrawableInstance from this DrawableSet. This will only work if the DrawableInstance belongs to this DrawableSet - it will not work if it belongs to another. Returns a true boolean value if the specified instance was found within this set and removed. If nothing was removed, a false value is returned.
public Remove ( DrawableInstance drawableInstance ) : bool
drawableInstance DrawableInstance
return bool

Remove() public method

Removes the DrawableInstance of the specified drawable from the specified set of this DrawableSet. Returns a true boolean value specifying if such an instance with the specified was found and removed. If nothing was removed, a false value is returned.
public Remove ( IGameDrawable drawable, string state ) : bool
drawable IGameDrawable
state string
return bool

Remove() public method

Performs Set negation between this DrawableSet and the DrawabelSet specified in the parameter. While two sets should never share the same DrawableInstance, they may share the same IGameDrawable which would be wrapped by an DrawableInstance. If the DrawableSet specified in the parameter contains IGameDrawables within the same state as this DrawableSet, then associated DrawableInstance's are removed.
public Remove ( DrawableSet drawableSet ) : void
drawableSet DrawableSet
return void

RemoveGroup() public method

public RemoveGroup ( string group ) : bool
group string
return bool

RemoveState() public method

public RemoveState ( string state ) : bool
state string
return bool

ResetGroup() public method

Asks all IGameDrawables within the specified *group* set to perform a Reset operation. By performing a Reset operation, each GameDrawable should act like it has just been created.
public ResetGroup ( string group, GameTime gameTime ) : void
group string
gameTime Microsoft.Xna.Framework.GameTime
return void

ResetState() public method

Asks all IGameDrawables within the specified *state* set to perform a Reset operation.
public ResetState ( string state, GameTime gameTime ) : void
state string
gameTime Microsoft.Xna.Framework.GameTime
return void

SetGroupProperty() public method

Sets the specified property for all the DrawableInstances in the specified group using C# Reflection. The property to be set should be specified as a case sensitive string and its value should be set with an type that matches the Properties type. If the property specified does not exist in the DrawableInstance class, then an ArgumentException is thrown.
public SetGroupProperty ( string group, string property, object value ) : void
group string
property string
value object
return void

SetStateProperty() public method

Sets the specified property for all the DrawableInstances in the specified state using C# Reflection. The property to be set should be specified as a case sensitive string and its value should be set with an type that matches the Properties type. If the property specified does not exist in the DrawableInstance class, then an ArgumentException is thrown.
public SetStateProperty ( string state, string property, object value ) : void
state string
property string
value object
return void

ToString() public method

public ToString ( ) : string
return string

Union() public method

Performs a Set union operation between this DrawableSet and the DrawableSet specified in the parameter. It is important to note that any IGameDrawables newly created in this DrawableSet are wrapped around a *new* DrawableInstance in order to allow properties to be set independently for each one.
public Union ( DrawableSet drawableSet ) : void
drawableSet DrawableSet
return void