Been looking around and cannot find anyone with this question and whos gotten an answer so I'm posting it here!

Is there anyway to use primitiveBatch and spriteBatch together in xna while using a 2D camera? Is there a way to apply that projection that is makes on the spriteBatch on the primitiveBatch?

有帮助吗?

解决方案

Well a 2d camera is just a matrix and luckily for us the Begin method of the spritbatch has a 2d transformation Parameter.

public void Begin (
     SpriteSortMode sortMode,
     BlendState blendState,
     SamplerState samplerState,
     DepthStencilState depthStencilState,
     RasterizerState rasterizerState,
     Effect effect,
     Matrix transformMatrix
)

Look right there at the bottom, the last parameter.

This means that all the subsequent draw calls between this and the end method of the spritebatch will have this transformation matrix apply to it.

If we wanted to abstract the drawing a little further i we could create our own camera class that would contain a property maybe that will return you the correct matrix for the current state of the camera.

A quick google search gave me this tutorial which seems good at showing how to abstract the use of matrices, and instead just use positions, scales and rotation. http://adambruenderman.wordpress.com/2011/04/05/create-a-2d-camera-in-xna-gs-4-0/

For more info look at http://msdn.microsoft.com/en-us/library/ff433701.aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top