Game Development Reference
In-Depth Information
{
_faceSprite.VertexPositions[i] *= m;
}
Experiment with the translation matrix as well, and try combining the matrices
in different orders.
Modifying the Sprite to Use Matrices
The sprite currently has a translation method SetPosition , but it doesn't
have similar SetScale or SetRotation methods. These would be very useful
functions to add and would be great to use with the tween functions. Modifying
the sprite class is quite simple but some additional members and methods need
to be added.
double _scaleX = 1;
double _scaleY = 1;
double _rotation = 0;
double _positionX = 0;
double _positionY = 0;
public void ApplyMatrix(Matrix m)
{
for (int i = 0; i < VertexPositions.Length; i++)
{
VertexPositions[i] *= m;
}
}
public void SetPosition(Vector position)
{
Matrix m = new Matrix();
m.SetTranslation(new Vector(_positionX, _positionY, 0));
ApplyMatrix(m.Inverse());
m.SetTranslation(position);
ApplyMatrix(m);
_positionX = position.X;
_positionY = position.Y;
}
 
Search WWH ::




Custom Search