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.

In my code below, I think it's correctly done. But idk, the image called by _bg is does not shown up. The screen only show White. Weirdly, there is 0 error message when I run it.

(The RenderTarget2D is for default-ing my view into landscape mode)

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameName2
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Game
    {
        GraphicsDeviceManager _graphics;
        SpriteBatch _spriteBatch;
        Texture2D _bg;

        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <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);

            _bg = Content.Load<Texture2D>(@"background");
            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            // TODO: Add your drawing code here
            _spriteBatch.Begin();
            _spriteBatch.Draw(_bg,
                new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height),
                null,
                Color.White,
                0,
                Vector2.Zero,
                SpriteEffects.None,
                0);
            _spriteBatch.End();

            base.Draw(gameTime);


        }
    }
}

I use xnb file. And I put it in Content folder in the project. I've set 'Content' and 'Copy if newer' to the file property.

This is the .png file I use before converted into xnb : https://imageshack.us/scaled/large/15/loadingo.png

Or maybe the problem is in my .png file?

Any idea? Thanks

share|improve this question

closed as too localized by Darth Satan, Anko, ClassicThunder, Byte56, msell Apr 30 '13 at 5:15

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

You should be using GraphicsDevice.Viewport instead of Window.ClientBounds when working with your SpriteBatch.

share|improve this answer
    
Why I wonder? What's the difference? –  Moses Aprico Apr 29 '13 at 14:52
1  
Works perfect. Thanks –  Moses Aprico Apr 29 '13 at 16:15
    
I can't tell you why, I just know it causes problems when you use Window.ClientBounds when drawing with SpriteBatch. It technically should work. –  Jon Apr 29 '13 at 18:43
    
Good call Jon. Perhaps this needs to be submitted as a bug in MonoGame? –  craftworkgames Apr 29 '13 at 22:58
    
msdn.microsoft.com/en-us/library/… has the answer as to what the difference is. Essentially ClientBounds.X is in screen space, not window. –  Phil Apr 30 '13 at 4:10

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