Click or drag to resize
PlanBaseAddSpriteAtPlan Method
Create a new (dynamic) instance of the specified sprite type at the first coordinate in this plan.

Namespace: (Default Namespace)
Assembly: Default (in Default.exe) Version: 1.0.0.0
Syntax
C#
public virtual void AddSpriteAtPlan(
	Type SpriteDefinition,
	RelativePosition RelativePosition
)

Parameters

SpriteDefinition
Type: SystemType
Specifies the type of sprite that will be created.
RelativePosition
Type: (Default Namespace)RelativePosition
Specified a coordinate within the sprite that should be matched up with the first coordinate of the plan.
Remarks

As opposed to ActivateSprite(SpriteBase), 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 ActivateSprite(SpriteBase) be used when more control is desired. However, AddSpriteAtPlan(Type, RelativePosition) 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.

All parameters of a newly created sprite instance are always initialized to zero. Furthermore, 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.

If this plan has no coordinates, the sprite is created at the top left corner of the layer, and not adjusted according to RelativePosition.

See Also