githubEdit

PropertyCollection

Introduction

PropertyCollections are a method of encapsulating a group of property values. Using PropertyCollections can simplify and make code more readable.

Using PropertyCollections

The following example creates a Spritearrow-up-right and sets its properties through a PropertyCollection.

Sprite sprite = SpriteManager.AddSprite("redball.bmp");

PropertyCollection propertyCollection = new PropertyCollection();
propertyCollection.Add("ScaleX", 5.0f);
propertyCollection.Add("RotationZ", (float)Math.PI / 8.0f);

propertyCollection.ApplyTo(sprite);
SpriteWithChangedProperties.png

Lack of Type Conversion in PropertyCollections

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:

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:

Instead, XVelocity must be explicitly given a float:

Did this article leave any questions unanswered? Post any question in our forumsarrow-up-right for a rapid response.

Last updated

Was this helpful?