0

I'm currently working on an RPG game using the XNA Framework.

Currently, when determining where text is displayed on the screen, I'm using trial and error method to find Y co-ordinates, i.e. loading up and then modifying the coordinate to alter the position.

The code sample below shows how I am processing the "Conversation" text

titleString = Fonts.SplitTextIntoLines(Conversation.CurrentNode.Text, Fonts.Font, new Vector2(maxWidth, 0));
titlePosition.X = (viewport.Width - Fonts.Font.MeasureString(titleString).X) / 2;
titlePosition.Y = backgroundPosition.Y + 200f;

Fonts.SplitTextIntoLines splits the input up into multiple lines depending on the Font used and the max width specified, this is irrelevant for my question

titlePosition.X: here I am centering the text on the screen

titlePosition.Y: This is the line I am bothered by

If there was some kind of tool which would allow me to have a blank window which I could position a piece of text, or image on and then see the coordinates, it would be a massive help.

If anyone knows of a tool like this, could you let me know? :)

Here is a screenshot to illustrate my question better http://img836.imageshack.us/img836/1929/i86g.png

  • How about you stop guessing and let the computer do the computing? For sure you can determine the rectangle within which your text can be displayed and then use `SpriteFont.MeasureString(string)` to find the length of your resulting text in pixels. Then it's just a couple of lines automating this for every line of text, pissibly even auto word wrapping and you don't ever need to do this manually again. http://stackoverflow.com/questions/10263734/how-to-align-text-drawn-by-spritebatch-drawstring and http://stackoverflow.com/questions/15986473/how-do-i-implement-word-wrap – user1306322 Jul 09 '13 at 08:56
  • I'm not talking about x-width, I have used MeasureString to wrap my text; Also my question isn't solely limited to text, it's about general position of anything... – James Robert Pattison Jul 10 '13 at 23:13

1 Answers1

0

The easy answer would be for you to implement a very basic tool to help to position your objects in your scene. Most game engine will have an editor for you to do so but since XNA is just a framework, you could implement a very simple system with your keyboard and arrow to move your text around and output on screen the X and Y position. It's not perfect but it should save you some time.

Also:

Vector2 mousePosition = new Vector2(Mouse.GetState().X,Mouse.GetState().Y);

Console.WriteLine("My Cursor is at: " + mousePosition);

Don't forget the IsMouseVisible member of Game to be able to actually see your mouse cursor.

Hope it helps!

Michael Dubé
  • 136
  • 1
  • 5