Currently I have the camera following an image, but now decided I want to display some text on the top of the screen. I have found using the following code it makes the text move around the screen as the location of 20, 20 is changing. (which makes sense as the camera is following an object, position 20, 20 is static).
spriteBatch.DrawString(font, "test", new Vector2(20, 20), Color.White);
The camera is being updated with the following code.
_viewMatrix = Matrix.CreateTranslation(new Vector3(-this.Position.X, -this.Position.Y, 0)) *
Matrix.CreateRotationZ(this.Rotation) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
Matrix.CreateTranslation(new Vector3(viewPort.Width * 0.5f, viewPort.Height * 0.5f, 0));
Its late, and feel I am missing something obvious, but if I want to always display "Test" of the screen regardless of where the camera is, how do you go about it?
Simple: Start another sprite batch (ie: call Begin), without passing a view matrix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With