2016-03-03 67 views
1

我目前回到MonoGame,但由於某種原因,我有一個問題繪製一個簡單的精靈到屏幕上。雪碧不出現在monogame?

我正在使用VS2015社區,創建了一個新的多平臺MonoGame項目,然後右鍵單擊Content文件夾並添加現有項目以將我的'player.png'圖像加載到項目中。

然後我寫了下面的代碼加載圖像並繪製到屏幕上:

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

namespace BulletHell 
{ 
/// <summary> 
/// This is the main type for your game. 
/// </summary> 
public class Game1 : Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 
    Texture2D playerImage; 
    Player player; 

    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() 
    { 
     player = new Player(100, 100, playerImage); 

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

     // TODO: use this.Content to load your game content here 
     playerImage = Content.Load<Texture2D>("player"); 
     player.Image = playerImage; 

    } 

    /// <summary> 
    /// UnloadContent will be called once per game and is the place to unload 
    /// game-specific 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) 
    { 
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) 
      Exit(); 

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

     // TODO: Add your drawing code here 
     spriteBatch.Begin(); 
     spriteBatch.Draw(playerImage, new Vector2(0, 0), Color.White); 
     spriteBatch.End(); 

     base.Draw(gameTime); 
    } 
} 
} 

任何想法,爲什麼不被顯示的精靈?

感謝

回答

0

在觀看你的代碼,我再次發現base.LoadContent();在您的LoadContent方法失蹤。如果你重新添加它,它應該畫它