Time for action – basic Sprite properties
Add public properties to allow access to the Sprite class' members:
public Vector2 Location { get { return location; } set { location = value; } } public Vector2 Velocity { get { return velocity; } set { velocity = value; } } public Color TintColor { get { return tintColor; } set { tintColor = value; } } public float Rotation { get { return rotation; } set { rotation = value % MathHelper.TwoPi; } }
What just happened?
The Location
, Velocity
, and TintColor
properties are simple pass-throughs for their underlying private members as no additional code or checks need to be done when these values are manipulated.
When Rotation
is set, the value is divided by MathHelper.TwoPi
and the remainder of the result is stored in the rotation
member. This is a shorthand way of keeping the value between 0 and 2*pi. If a value within this range is passed into Rotation
, the remainder of the division will equal the passed value. If the...