C# 4.0 Content.Load<;纹理2d>;(“圆形”);找不到Round.png文件

C# 4.0 Content.Load<;纹理2d>;(“圆形”);找不到Round.png文件,c#-4.0,xna,C# 4.0,Xna,可能重复: 在这里,我试图在WindowsPhone7应用程序项目中加载一个Round.png文件。我不知道如何在运行时加载此映像。如果这是一个愚蠢的问题,我真的很抱歉,因为我是windows应用程序开发的新手。请帮忙。。。 提前感谢 /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.X

可能重复:

在这里,我试图在WindowsPhone7应用程序项目中加载一个Round.png文件。我不知道如何在运行时加载此映像。如果这是一个愚蠢的问题,我真的很抱歉,因为我是windows应用程序开发的新手。请帮忙。。。 提前感谢

     /// <summary>
     /// This is the main type for your game
     /// </summary>
   public class Game1 : Microsoft.Xna.Framework.Game
   {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Texture2D texRound;
    Rectangle HitRegion;
    bool isSelected = false;

    TouchCollection touches = TouchPanel.GetState();

    //start position of round, in the center of screen
    int positionX = 400;
    int positionY = 240;

    //random number Axis X and Y
    Random randomX;
    Random randomY;

    //the range for random number of start and end of X, Y
    int startX, endX;
    int startY, endY;

    //total time
    float milliseconds = 0f;

    //score count
    int count = 0;

    //game font
    SpriteFont font;

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

        // Frame rate is 30 fps by default for Windows Phone.
        TargetElapsedTime = TimeSpan.FromTicks(333333);

        // Extend battery life under lock.
        InactiveSleepTime = TimeSpan.FromSeconds(1);
    }

    /// <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);
        texRound = Content.Load<Texture2D>("Round");
        randomX = new Random();
        randomY = new Random();

        // The X axis bound range of touch for ball
        startX = texRound.Width;
        endX = GraphicsDevice.Viewport.Width - texRound.Width;

        // The X axis bound range of touch for ball
        startY = texRound.Height;
        endY = GraphicsDevice.Viewport.Height - texRound.Height;

        // Define the HitRegion of ball in the middle of touchscreen
        HitRegion = new Rectangle(positionX - texRound.Width / 2,
        positionY - texRound.Height / 2, texRound.Width,
        texRound.Height);

        // Load the font definition file
        font = Content.Load<SpriteFont>("gamefont");

        // 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)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        // Accumulate the elapsed milliseconds every frame
        milliseconds +=
        (float)gameTime.ElapsedGameTime.TotalMilliseconds;
        if (milliseconds > 1000)
        {
            // When the milliseconds greater than 1000 milliseconds,
            // randomly locate a new position for the ball
            HitRegion.X = randomX.Next(startX, endX + 1);
            HitRegion.Y = randomY.Next(startY, endY + 1);
            // Reset the milliseconds to zero for new milliseconds
            // count
            // make the ball not been selected
            milliseconds = 0f;
            if (isSelected)
                isSelected = false;
        }
        base.Update(gameTime);

        Point touchPoint = new Point((int)touches[0].Position.X, (int)touches[0].Position.Y);
        if (HitRegion.Contains(touchPoint))
        {
            isSelected = true;
            count++;
        }
        else
        {
            isSelected = false;
        }
    }

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

        // TODO: Add your drawing code here

        spriteBatch.Begin();
        if (isSelected)
        {
            spriteBatch.Draw(texRound, HitRegion, Color.Red);
        }
        else
        {
            spriteBatch.Draw(texRound, HitRegion, Color.White);
        }
        spriteBatch.DrawString(font, "Score:" + count.ToString(),
        new Vector2(0f, 0f), Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}
//
///这是游戏的主要类型
/// 
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
纹理2d-texRound;
矩形区域;
bool-isSelected=false;
TouchCollection touchs=TouchPanel.GetState();
//圆的起始位置,在屏幕中央
int位置x=400;
int位置y=240;
//X轴和Y轴上的随机数
随机随机X;
随机性;
//X,Y的起点和终点的随机数范围
int startX,endX;
int startY,endY;
//总时间
浮点毫秒=0f;
//计分
整数计数=0;
//游戏字体
SpriteFont字体;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
//Windows Phone的帧速率默认为30 fps。
targetExpressedTime=时间跨度(333);
//在锁定状态下延长电池寿命。
InactiveSleepTime=时间跨度(从秒开始)(1);
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
//TODO:在此处添加初始化逻辑
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
texRound=Content.Load(“Round”);
randomX=新的Random();
randomY=新的Random();
//球的X轴接触范围
startX=texRound.宽度;
endX=GraphicsDevice.Viewport.Width-texRound.Width;
//球的X轴接触范围
startY=texRound.高度;
endY=GraphicsDevice.Viewport.Height-texRound.Height;
/在触摸屏中间定义球的HIT区
HitRegion=新矩形(位置X-texRound.Width/2,
位置Y-texRound.高度/2,texRound.宽度,
(四舍五入),;
//加载字体定义文件
font=Content.Load(“gamefont”);
//TODO:使用此.Content在此处加载游戏内容
}
/// 
///UnloadContent将在每个游戏中调用一次,并且是卸载的地方
///所有内容。
/// 
受保护的覆盖无效UnloadContent()
{
//TODO:在此卸载任何非ContentManager内容
}
/// 
///允许游戏运行逻辑,例如更新世界,
///检查碰撞、收集输入和播放音频。
/// 
///提供计时值的快照。
受保护覆盖无效更新(游戏时间游戏时间)
{
//允许游戏退出
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)
这是Exit();
//TODO:在此处添加更新逻辑
//每帧累积经过的毫秒数
毫秒+=
(float)gameTime.ElapsedGameTime.Total毫秒;
如果(毫秒>1000)
{
//当毫秒数大于1000毫秒时,
//随机定位球的新位置
HitRegion.X=randomX.Next(startX,endX+1);
HitRegion.Y=randomY.Next(开始,结束+1);
//对于新毫秒,将毫秒重置为零
//计数
//使球未被选中
毫秒=0f;
如果(当选)
isSelected=false;
}
更新(游戏时间);
点接触点=新点((int)接触[0]。位置.X,(int)接触[0]。位置.Y);
if(HitRegion.Contains(接触点))
{
isSelected=true;
计数++;
}
其他的
{
isSelected=false;
}
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色。绿色);
//TODO:在此处添加图形代码
spriteBatch.Begin();
如果(当选)
{
spriteBatch.Draw(特克斯圆形、HitRegion、彩色、红色);
}
其他的
{
spriteBatch.Draw(特克斯圆形、HitRegion、彩色、白色);
}
spriteBatch.DrawString(字体,“Score:+count.ToString(),
新矢量2(0f,0f),颜色为白色;
spriteBatch.End();
基础。抽签(游戏时间);
}
}


我假设您正确地将Round.png文件放入了内容目录(或项目)中,并且按照默认设置正确地编译了它


右键单击该文件并打开其属性。检查“名称”字段。这就是
Content.Load
所期望的。例如,如果您将一个名为“Circular.png”的文件拖动到内容文件夹中,则该文件将自动命名为“Circular”,但如果您将该文件重命名为“Round.png”,则该文件通常将保持命名为“Circular”,让您手动更改属性中的名称并更新代码中的所有引用。

内部异常中的路径看起来正确:
\“C