XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

NIce looking text menu.

Last post 10/17/2008 1:03 PM by John Sedlak. 2 replies.
  • 10/16/2008 3:50 AM

    NIce looking text menu.

    Hello. I already created my menu with the following code, but it looks to simple, I would like the text to be more well designed, I dont know, maybe shadow or something else.

     

    Can you point me  to the right direction please?

     

    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    #endregion

    namespace MayoFighter
    {
        public class menu
        {
            private static int MAX = 20;
            private int menuItemCount;
            private int curMenuItem;
            private string[ menuItems;
            private Vector2[ pos;
            private double[ scale;
            private Color unselected;
            private Color selected;
            private SpriteFont font;

            public menu(Color unslectedColor, Color selectedColor, SpriteFont sp)
            {
                font = sp;
                menuItems = new string[MAX];
                pos = new Vector2[MAX];
                scale = new double[MAX];
                unselected = unslectedColor;
                selected = selectedColor;
                menuItemCount = 0;
                curMenuItem = 0;
            }

            public void addMenuItem(string name, Vector2 p)
            {
                if (menuItemCount < MAX)
                {
                    menuItems[menuItemCount] = name;
                    scale[menuItemCount] = 1.0f;
                    pos[menuItemCount++] = p;
                }
            }

            public void update(GameTime gameTime)
            {
                for (int x = 0; x < menuItemCount; x++)
                {
                    if (x == curMenuItem)
                    {
                        if (scale[x] < 2.0f)
                        {
                            scale[x] += 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                            //pos[x].Y += 0.04f + 10.0f * gameTime.ElapsedGameTime.Seconds;
                        }
                    }
                    else if (scale[x] > 1.0f && x != curMenuItem)
                    {
                        scale[x] -= 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                        //pos[x].Y -= 0.04f + 10.0f * gameTime.ElapsedGameTime.Seconds;

                    }
                }
            }

            public void Draw(SpriteBatch spriteBatch)
            {
                spriteBatch.Begin();
                for (int x = 0; x < menuItemCount; x++)
                {
                    if (x == curMenuItem)
                    {
                        Vector2 p = pos[x];
                        p.X += (float)(22 * scale[x] / 2);
                        p.Y -= (float)(22 * scale[x] / 2);
                        spriteBatch.DrawString(font,
                                               menuItems[x],
                                               p,
                                               selected,
                                               0.0f,
                                               new Vector2(0, 0),
                                               (float)scale[x],
                                               SpriteEffects.None,
                                               0);
                    }
                    else
                    {
                        Vector2 p = pos[x];
                        p.X -= (float)(22 * scale[x] / 2);
                        p.Y -= (float)(22 * scale[x] / 2);
                        spriteBatch.DrawString(font,
                                               menuItems[x],
                                               p,
                                               unselected,
                                               0.0f,
                                               new Vector2(0, 0),
                                               (float)scale[x],
                                               SpriteEffects.None,
                                               0);
                    }
                }
                spriteBatch.End();
            }

            public int getSelectedNum()
            {
                return curMenuItem;
            }

            public string getSelectedName()
            {
                return menuItems[curMenuItem];
            }

            public void selectNext()
            {
                if (curMenuItem < menuItemCount - 1)
                {
                    curMenuItem++;
                }
                else
                {
                    curMenuItem = 0;
                }
            }

            public void selectPrev()
            {
                if (curMenuItem > 0)
                {
                    curMenuItem--;
                }
                else
                {
                    curMenuItem = menuItemCount - 1;
                }
            }

        }
    }


  • 10/16/2008 4:16 AM In reply to

    Re: NIce looking text menu.

    If you want full control over how your menu items look, you can draw each one of them in a drawing package like Photoshop or Paint .NET, and then draw them as quads with a texture. You can use whatever font and effects you want in that case.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 10/17/2008 1:03 PM In reply to

    Re: NIce looking text menu.

    jwatte:
    If you want full control over how your menu items look, you can draw each one of them in a drawing package like Photoshop or Paint .NET, and then draw them as quads with a texture. You can use whatever font and effects you want in that case.
    Or use the bitmap font generator to create a font texture. Then modify that texture in Photoshop, etc. Text is only one part of a textual menu though... http://videos.focusedgames.com/GW_101608.wmv
    John Sedlak Xna/DirectX MVP
    XNA Articles, Tutorials and Videos | My Blog
Page 1 of 1 (3 items) Previous Next