I'm building a framework for XNA where users can use the hierarchy pattern to manage the display objects, meaning the transformation matrices of parents are applied to the children as well.
Users could set translation, scale and rotation, which are internally converted into a matrix when combining the transformations and drawing (users were also able to retrieve the transformation matrix).
The SpriteBatch.Draw()
method doesn't have any overloads that has a matrix as a parameter, but I could just use Matrix.Decompose()
to get the necessary components out of the concatenated matrix.
Now the problem is, I decided to allow users to directly set the matrix of individual objects (instead of it being read-only), meaning users can apply more complex transformations such as skewing. However a matrix with such transformation can't be decomposed into translation, scale and rotation, meaning I can no longer pass the transformation information to the SpriteBatch.Draw()
method.
The only solution I've found so far, is to call SpriteBatch.Begin()
for every individual object, passing its concatenated matrix as a parameter. I'm sure this isn't a usable solution at all, since sprite batch wouldn't be a batch anymore if I begin and end the batch for every call to Draw()
.
tl;dr: How can I apply a transformation matrix rather than components to each 2D object, without having to call SpriteBatch.Begin()
for every object?
Edit: I do not want to settle with my solution of calling Begin()
and End()
for every object drawn on the screen.