C# 精灵不出现在游戏中?

C# 精灵不出现在游戏中?,c#,visual-studio,monogame,C#,Visual Studio,Monogame,我现在又回到了MonoGame,但由于某些原因,我在屏幕上绘制一个简单的精灵时遇到了问题 我正在使用VS2015社区,创建了一个新的多平台单游戏项目,然后右键单击内容文件夹并添加现有项目,将我的“player.png”图像加载到项目中 然后,我编写了以下代码来加载图像并绘制到屏幕: using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input;

我现在又回到了MonoGame,但由于某些原因,我在屏幕上绘制一个简单的精灵时遇到了问题

我正在使用VS2015社区,创建了一个新的多平台单游戏项目,然后右键单击内容文件夹并添加现有项目,将我的“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);
    }
}
}
使用Microsoft.Xna.Framework;
使用Microsoft.Xna.Framework.Graphics;
使用Microsoft.Xna.Framework.Input;
命名空间BulletHell
{
/// 
///这是游戏的主要类型。
/// 
公共类游戏1:游戏
{
图形管理器图形;
SpriteBatch SpriteBatch;
纹理2D播放器图像;
玩家;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
玩家=新玩家(100,100,玩家图像);
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
playerImage=Content.Load(“播放器”);
player.Image=playerImage;
}
/// 
///UnloadContent将在每个游戏中调用一次,并且是卸载的地方
///游戏特定内容。
/// 
受保护的覆盖无效UnloadContent()
{
//TODO:在此卸载任何非ContentManager内容
}
/// 
///允许游戏运行逻辑,例如更新世界,
///检查碰撞、收集输入和播放音频。
/// 
///提供计时值的快照。
受保护覆盖无效更新(游戏时间游戏时间)
{
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed | | | Keyboard.GetState().IsKeyDown(Keys.Escape))
退出();
//TODO:在此处添加更新逻辑
更新(游戏时间);
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色。黑色);
//TODO:在此处添加图形代码
spriteBatch.Begin();
spriteBatch.Draw(playerImage,新矢量2(0,0),彩色,白色);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
}
知道为什么没有显示精灵吗


谢谢

再次查看您的代码时,我注意到
base.LoadContent()。如果你再加上这个,它应该画出来