Jump to content
  • Advertisement
Sign in to follow this  
Bruno Filip

XNA coordinate drawing

This topic is 833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy everyone.

 

I have this problem, I have a background pic that is like idk 1200 x 1600 an my xna window is lik idk 500 x 400 so this bckgnd pic is basiclly a small map for my game, and I made an animated sprite and camera that follows her anywhere on the map.

 

Now, I'm printing some helpful text that when I press tab I should see her coordinates on left top corner of my screen BUT here is the problem, 

lets say I did something like this:

spriteBatch.DrawString(font, ("X:" + katrina.position.X +  "\nY:" + katrina.position.Y), new Vector2(10, 10),Color.White);

Now ofcourse the text will always stay in that left top corner of the map, but not my window, cause If i move to like idk 1000x1000 my camera will be showing my player and I wont be able to see text thats on x:10, y:10

 

So my question is: How do I make this Helpful text always stay on top left corner of the window and not on specific coordinates of my 'map' :/ ?

Share this post


Link to post
Share on other sites
Advertisement

Draw it with a different camera. IIRC, the only notion SpriteBatch has of a camera is the matrix that is passed into SpriteBatch.Begin, right? So you must be using that to draw your map.

 

So use a different begin/end batch for the HUD elements. The overload of Begin that doesn't take a matrix with draw things relative to the top left of the screen.

Share this post


Link to post
Share on other sites

Okay now I added this DrawHud method, and:

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            DrawHud(spriteBatch, gameTime); // calling DrawHud
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null,null, Cam.transform);
            
            spriteBatch.Draw(bckgndT, bckgndR, null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1);
            katrina.Draw(spriteBatch);
            if (HelpTxtVisible)
                spriteBatch.DrawString(font, ("X:" + katrina.position.X + "\nY:" + katrina.position.Y), new Vector2(katrina.position.X, katrina.position.Y - 70),Color.White);

            spriteBatch.End();
            base.Draw(gameTime);
        }

        public void DrawHud(SpriteBatch spriteBatch2, GameTime gameTime)
        {
            spriteBatch2.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            spriteBatch.DrawString(font, ("Test"), new Vector2(10, 10), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
            spriteBatch2.End();
            base.Draw(gameTime);
        }

It works, the Text is always in 1 place, but my bckgnd image is on top of Test string, I messed around with layerdepth but cant get it right :/ ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!