Probably the easiest way to do this in XNA is to pass a Matrix
to SpriteBatch.Begin
. This is the overload you want to use: MSDN (the transformMatrix
argument).
You can also do this with raw vertices, with an effect like BasicEffect
by setting its World
matrix. Or by setting vertex positions manually, perhaps transforming them with Vector3.Transform()
.
Most of the transformation matrices you want are provided by the Matrix.Create*()
methods (MSDN). For example, CreateScale
and CreateRotationZ
.
There is no provided method for creating a skew matrix. It should be something like this:
Matrix skew = Matrix.Identity;
skew.M12 = (float)Math.Tan(MathHelper.ToRadians(36.87f));
(That is to skew by 36.87f degrees, which I pulled off this old answer of mine. You should be able to find the full maths for a skew matrix via Google.)
Remember that transformations happen around the origin of world space (0,0). If you want to, for example, scale around the centre of your sprite, you need to translate that sprite's centre to the origin, apply a scale, and then translate it back again. You can combine matrix transforms by multiplying them. This example (untested) will scale a 200x200 image around its centre:
Matrix myMatrix = Matrix.CreateTranslation(-100, -100, 0)
* Matrix.CreateScale(2f, 0.5f, 1f)
* Matrix.CreateTranslation(100, 100, 0);
Note: avoid scaling the Z axis to 0, even in 2D.
For perspective there is CreatePerspective
. This creates a projection matrix, which is a specific kind of matrix for projecting a 3D scene onto a 2D display, so it is better used with vertices when setting (for example) BasicEffect.Projection
. In this case you're best off doing proper 3D rendering.
For distort, just use vertices and place them manually wherever you need them.