示例#1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // load the texture for the virtual keyboard dialog
            m_VirtualKeyboard.Texture =
                Content.Load<Texture2D>(@"media\virtualkeyboard");

            // create our bitmap font, share it with the virtual keyboard
            m_font = GameFont.FromTexture2D(
                Content.Load<Texture2D>(@"media\font"));
            m_VirtualKeyboard.Font = m_font;
        }
示例#2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // load our font textures, create corresponding game fonts
            m_fontVerdana = GameFont.FromTexture2D(
                Content.Load<Texture2D>(@"fonts\Verdana12Bold"));
            m_fontMistral = GameFont.FromTexture2D(
                Content.Load<Texture2D>(@"fonts\Mistral11"));
        }
示例#3
0
        // given a texture with encoded glyphs, return a BitmapFont object
        public static GameFont FromTexture2D(Texture2D texture)
        {
            // new instance placeholder
            GameFont font = null;

            // first, make sure it's a valid texture
            if (texture == null)
            {
                throw new GameFontException("Texture2D cannot be null.");
            }
            else
            {
                // try to extract the glyphs from the texture
                font = new GameFont();
                font.Texture = texture;
                font.ExtractGlyphDescriptors();
            }

            // return the fruits of our labor
            return font;
        }
示例#4
0
        // render animated text, moves according to m_angle
        protected void DrawWavingText(SpriteBatch batch,
            GameFont font, char[] letters, Color color)
        {
            // top left of text, if it were drawn just below
            // the vertical center of the screen
            int x = 32;
            int y = SCREEN_HEIGHT / 2;

            // vary the top location of each character
            int dy = 0;
            for (int i = 0; i < letters.Length; i++)
            {
                // simple sin function to produce a wave from -20.0f to +20.0f
                dy = (int)Math.Round(
                    Math.Sin(MathHelper.ToRadians(m_fAngle + (i * 10))) *
                    20.0f);
                // render each letter seperately
                x += (int)font.DrawString(batch,
                    letters[i], x, y + dy, color).X;
            }
        }