Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

First thing, I am not a seasoned game developer. I am using game development as a conduit to learn programming.

I am attempting to put the player names above the player's head's. I am using a variation of Shawn Hargreaves solution;

            basicEffect.World = Matrix.CreateConstrainedBillboard(textPosition, textPosition - cameraFront, Vector3.Down, null, null);
            basicEffect.View = view;
            basicEffect.Projection = projection;

            const string message = "hello, world!";
            Vector2 textOrigin = spriteFont.MeasureString(message) / 2;
            const float textSize = 0.25f;
            spriteBatch.Begin(0, null, null, DepthStencilState.DepthRead, RasterizerState.CullNone, basicEffect);
            spriteBatch.DrawString(spriteFont, message, Vector2.Zero, Color.White, 0, textOrigin, textSize, 0, 0);
            spriteBatch.End();

My game is space based, so I needed the text to rotate on all 3 axes, so I implemented the following;

        foreach (PlayerShip objPlayerShip in objPlayers)
        {
            Vector3 objTextPosition = objPlayerShip.objShipVector + new Vector3(0, 3, 0);
            Vector3 objCameraFront = objManager.objCamera.objCameraPostion;

            objBasicEffect.World = Matrix.CreateBillboard(objTextPosition, objCameraFront, objManager.objCamera.objCameraUp, null);
            objBasicEffect.View = objManager.objCamera.objViewMatrix;
            objBasicEffect.Projection = objManager.objCamera.objProjectionMatrix;

            string strText = objPlayerShip.strGUID.ToString();
            Vector2 objTextOrgin = objCourierNew.MeasureString(strText) / 2;

            spriteBatch.Begin(0, null, null, DepthStencilState.Default, RasterizerState.CullNone, objBasicEffect);
            spriteBatch.DrawString(objCourierNew, strText, Vector2.Zero, Color.Green, 0, objTextOrgin, 0.09f, SpriteEffects.None, 0.0f);
            spriteBatch.End();

        }

It seems to be working, but the text is upside down. How would I flip the text right side up? I know I have to change something in objBasicEffect.World. I try to tweak it, but I just make things worse...

Any help would be appreciated. Linuxx

share|improve this question
    
My guess would be that you want to pass Vector3.Up instead of Vector3.Down to CreateConstrainedBillboard() –  Adam Jan 7 '13 at 0:21
    
Well, I exchanged CreateConstrainedBillboard() for CreateBillboard() because it's spherical, as apposed to cylindrical (as you can see from my code). I need the text to be available regardless of the orientation. CreateConstrainedBillboard() would appear "on edge" and not be readable if you were looking at the text from above, or below. –  Linuxx Jan 7 '13 at 1:10
    
As it appears my text was both upside down, and backwards. I solved this with; spriteBatch.DrawString(objCourierNew, strText, Vector2.Zero, Color.Green, 0, objTextOrgin, 0.09f, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically, 0.0f); I feel really stupid it was so basic... :-/ Then again, I did learn how to combine enum's! Thanks for your help Adam. –  Linuxx Jan 7 '13 at 2:17
    
@Linuxx Even if you've solved your own question, you should write an answer and accept it :) –  Andrew Russell Jan 7 '13 at 4:40
add comment

1 Answer

As it appears my text was both upside down, and backwards. I solved this with;

spriteBatch.DrawString(objCourierNew, strText, Vector2.Zero, Color.Green, 0, objTextOrgin, 0.09f, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically, 0.0f);

I feel really stupid it was so basic... :-/

Then again, I did learn how to combine enum's!

Thanks for your help Adam.

p.s. I couldn't answer my own question until 8 hours had passed. I'm a new user...

Linuxx

share|improve this answer
1  
There's no shame in learning from an error. :) It's also completely fine to mark your own answer as accepted. (In this case, it may help future visitors.) –  Anko Jan 14 '13 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.