Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xna draw text to screen when camera following object

Tags:

xna

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?

like image 560
Simon Avatar asked Oct 18 '25 06:10

Simon


1 Answers

Simple: Start another sprite batch (ie: call Begin), without passing a view matrix.

like image 165
Andrew Russell Avatar answered Oct 21 '25 03:10

Andrew Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!