Example #1
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;
        }
Example #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 the main game texture
            m_GameTexture =
                Content.Load<Texture2D>(@"media\brickbreaker");

            // extract the opaque data from the sprite images
            PaddleOpaqueData =
                PixelPerfectHelper.GetOpaqueData(m_spritePaddle);
            BallOpaqueData =
                PixelPerfectHelper.GetOpaqueData(m_spriteBall);
            BrickOpaqueData =
                PixelPerfectHelper.GetOpaqueData(new BrickSprite());

            // initialize our game font
            m_GameFontTexture =
                Content.Load<Texture2D>(@"media\Verdana8Bold");
            m_GameFont = GameFont.FromTexture2D(m_GameFontTexture);
        }