Unlike assigning properties using regular code the values assigned to properties through PropertyCollections must match the type exactly. For example the following code is acceptable:
// Assuming someSprite is a valid Sprite.
someSprite.XVelocity = 3;
The value of 3 is an integer value, as opposed to 3.0f, but the compiler casts the value to a float without any problem. However, the following code would result in a crash:
// Assuming someSprite is a valid Sprite and propertyCollection is a valid PropertyCollection
propertyCollection.Add("XVelocity", 3); // OH NO, 3 is an int!
propertyCollection.ApplyTo(someSprite); // This will throw an assert.
Instead, XVelocity must be explicitly given a float:
// Assuming someSprite is a valid Sprite and propertyCollection is a valid PropertyCollection
propertyCollection.Add("XVelocity", 3.0f); // Whew, 3.0f is a float.
propertyCollection.ApplyTo(someSprite); // This will now work fine.
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.