SpriteBaseTileAddSprite Method |
Namespace: (Default Namespace)
public virtual void TileAddSprite( int TouchingIndex, Type SpriteDefinition )
As opposed to TileActivateSprite(Int32, SpriteCollection, Boolean), which activates a pre-defined instance of a sprite, this function will actually create a new sprite instance on the fly (referred to as a "dynamic" sprite instance). Dynamic sprites cannot be referred to directly by other rules because they don't have names associated with them, therefore it's recommended that TileActivateSprite(Int32, SpriteCollection, Boolean) be used when more control is desired. However, for common sprites that may be created on any map, this is ideal because it doesn't require you to pre-define each possible instance.
Dynamic sprites are added to the end of each category that they belong to (categories are defined in terms of sprite definitions, so a dynamic sprite knows the categories in which it should participate). This happens as the sprite is created. When the sprite is deactivated, it will automatically be removed from all categories as part of ProcessSprites.
The maximum number of sprites that can be active on a layer at once is defined by maxCollectionSize. This includes static sprites as well as dynamic sprites. The purpose of this maximum is not a technical limitation (feel free to change the code in SpriteCollection.cs to increase the maximum all you like). It only exists to help developers realize when sprite instances are "leaking" (not being cleaned up or deactivated properly) or when more sprites than necessary are being created. In many cases, the engine can actually handle quite a bit more than 100 sprites without significant performance impact.
Because the sprite instances being created are not activations of already existing instances (as is the case with TileActivateSprite(Int32, SpriteCollection, Boolean)), there is no need for a parameter to reset all the sprite's parameters. All parameters of a newly created sprite instance are always initialized to zero. The solidity is copied from the sprite definition that created the sprite.
New sprite instances will not refer to any solidity, and will begin in the first frame of the first state, but you can use rules to affect lastCreatedSprite to set values of the new sprite, or define rules on the created sprite type to make it initialize itself appropriately.