C# XNA中构建后未启动游戏项目
我是XNA游戏开发的新手,目前正在练习制作游戏 我首先创建了一个简单的平台,然后慢慢地建立了游戏的逻辑和游戏功能。我最近添加的内容似乎破坏了该项目。它是在添加了一个健康栏函数后开始的,我在其中添加了11个纹理(健康栏为空、健康栏1/10、健康栏2/10等) 当玩家在游戏中遇到有害对象(如钉子)时,健康栏显示的纹理将发生变化(因此,如果健康栏处于9,纹理将变为健康栏8) 该问题最初是由于在两个不同的VisualStudio窗口中打开同一项目的两个窗口而导致的实际错误,阻止了项目的生成。(这太愚蠢了,我在谷歌上搜索如何修复给定的错误,然后才发现我打开了两个窗口)。建议的修复方法是在预构建命令行框中输入以下两行: 如果存在“$(TargetPath).locked“del”$(TargetPath).locked” 如果存在“$(TargetPath)”如果不存在“$(TargetPath).锁定“移动”$(TargetPath)”“$(TargetPath).锁定” 这似乎已经修复了错误,但现在我的项目只生成而不启动,因此我关闭了我发现打开的额外窗口,并从预生成命令行框中删除了两行,但现在项目只生成而不启动 我试着创建一个新项目,检查它是否构建了(确实构建了,所以VisualStudio本身并不是问题所在),然后将损坏的项目代码复制并粘贴到这个新项目中,这个项目仍然没有启动 我不知道是什么原因造成的,这是非常恼人的。如果我的问题陈述得不好,我真的很抱歉,因为这是我的第一个堆栈溢出问题(因为我从来没有感觉到有必要在互联网上发布问题),但我在大量的谷歌搜索后找不到解决方案C# XNA中构建后未启动游戏项目,c#,visual-studio-2010,xna,C#,Visual Studio 2010,Xna,我是XNA游戏开发的新手,目前正在练习制作游戏 我首先创建了一个简单的平台,然后慢慢地建立了游戏的逻辑和游戏功能。我最近添加的内容似乎破坏了该项目。它是在添加了一个健康栏函数后开始的,我在其中添加了11个纹理(健康栏为空、健康栏1/10、健康栏2/10等) 当玩家在游戏中遇到有害对象(如钉子)时,健康栏显示的纹理将发生变化(因此,如果健康栏处于9,纹理将变为健康栏8) 该问题最初是由于在两个不同的VisualStudio窗口中打开同一项目的两个窗口而导致的实际错误,阻止了项目的生成。(这太愚蠢了
public class MainGame : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont coinCount;
List<PlatformSprite> platformsList;
List<Consumable> pickUpList;
List<StaticEnemy> staticEnemyList;
//public Texture2D currentHealthTexture;
//Texture2D healthEmpty;
//Texture2D health1;
//Texture2D health2;
//Texture2D health3;
//Texture2D health4;
//Texture2D health5;
//Texture2D health6;
//Texture2D health7;
//Texture2D health8;
//Texture2D health9;
//Texture2D healthFull;
//List<Texture2D> healthBarsList;
Texture2D coinAnim;
Texture2D coinAnimBig;
Texture2D floatingPlatform;
Texture2D groundPlatform;
Texture2D redPlayer;
Texture2D spikeEnemy;
Rectangle destRect;
Rectangle sourceRect;
Rectangle destRectSmall;
Rectangle sourceRectSmall;
PlayerSprite player;
KeyboardState keyboardState;
float elapsed;
float delay = 90f;
int frameCount = 0;
public const int screenHeight = 550;
public const int screenWidth = 800;
public MainGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferHeight = screenHeight;
graphics.PreferredBackBufferWidth = screenWidth;
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()
{
destRect = new Rectangle(100, 100, 60, 60);
destRectSmall = new Rectangle(100, 300, 20, 20);
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);
coinCount = Content.Load<SpriteFont>("CoinCount");
platformsList = new List<PlatformSprite>();
pickUpList = new List<Consumable>();
//healthBarsList = new List<Texture2D>();
staticEnemyList = new List<StaticEnemy>();
coinAnim = Content.Load<Texture2D>("CoinSpinAnim");
coinAnimBig = Content.Load<Texture2D>("CoinAnim");
floatingPlatform = Content.Load<Texture2D>("Platform1");
groundPlatform = Content.Load<Texture2D>("GroundPlatform1");
redPlayer = Content.Load<Texture2D>("TestSprite");
spikeEnemy = Content.Load<Texture2D>("Spike");
//healthEmpty = Content.Load<Texture2D>("HealthBarEmpty");
//health1 = Content.Load<Texture2D>("HealthBar1");
//health2 = Content.Load<Texture2D>("HealthBar2");
//health3 = Content.Load<Texture2D>("HealthBar3");
//health4 = Content.Load<Texture2D>("HealthBar4");
//health5 = Content.Load<Texture2D>("HealthBar5");
//health6 = Content.Load<Texture2D>("HealthBar6");
//health7 = Content.Load<Texture2D>("HealthBar7");
//health8 = Content.Load<Texture2D>("HealthBar8");
//health9 = Content.Load<Texture2D>("HealthBar9");
//healthFull = Content.Load<Texture2D>("HealthBarFull");
//healthBarsList.Add(healthEmpty);
//healthBarsList.Add(health1);
//healthBarsList.Add(health2);
//healthBarsList.Add(health3);
//healthBarsList.Add(health4);
//healthBarsList.Add(health5);
//healthBarsList.Add(health6);
//healthBarsList.Add(health7);
//healthBarsList.Add(health8);
//healthBarsList.Add(health9);
//healthBarsList.Add(healthFull);
platformsList.Add(new PlatformSprite(groundPlatform, new Vector2(0, 454)));
platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(500, 330)));
platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(100, 290)));
platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(300, 250)));
platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(170, 250)));
platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(350, 360)));
staticEnemyList.Add(new StaticEnemy(spikeEnemy, platformsList[0], 300));
pickUpList.Add(new Consumable(coinAnim, platformsList[1], 30, sourceRectSmall));
pickUpList.Add(new Consumable(coinAnim, platformsList[3], 45, sourceRectSmall));
pickUpList.Add(new Consumable(coinAnim, platformsList[4], 60, sourceRectSmall));
player = new PlayerSprite(redPlayer, platformsList, pickUpList, staticEnemyList, 0);
}
/// <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();
keyboardState = Keyboard.GetState();
//currentHealthTexture = healthBarsList[player.playerHealth];
player.Update(keyboardState);
elapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
if (elapsed >= delay)
{
if (frameCount >= 5)
{
frameCount = 0;
}
else
{
frameCount++;
}
elapsed = 0;
}
sourceRect = new Rectangle(60 * frameCount, 0, 60, 60);
sourceRectSmall = new Rectangle(20 * frameCount, 0, 20, 20);
foreach (Consumable c in pickUpList)
{
c.Update();
}
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.CornflowerBlue);
spriteBatch.Begin();
foreach (PlatformSprite p in platformsList)
{
p.Draw(spriteBatch);
}
foreach (Consumable c in pickUpList)
{
c.Draw(spriteBatch, sourceRectSmall);
}
foreach (StaticEnemy se in staticEnemyList)
{
se.Draw(spriteBatch);
}
//spriteBatch.Draw(currentHealthTexture, new Vector2(680, 10), Color.White);
spriteBatch.DrawString(coinCount, ": " + player.playerCoinCount, new Vector2(30, 10), Color.White);
spriteBatch.Draw(coinAnim, new Rectangle(10, 10, 20, 20), new Rectangle(0, 0, 20, 20), Color.White);
player.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
public类主游戏:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
斯普里特丰硬币计数;
列表平台列表;
列表选择器;
列表静态列表;
//公共结构2d当前健康结构;
//纹理2d为空;
//结构2d健康1;
//质地2 d健康2;
//质地2 d健康3;
//质地2 d健康4;
//质地2 d健康5;
//质地2 d健康6;
//质地2d-7;
//结构2d-8;
//质地2 d健康9;
//纹理2d健康饱满;
//列出健康酒吧名单;
纹理2d-coinAnim;
纹理2d大;
纹理2d浮动平台;
纹理2d地面平台;
纹理2D红色播放器;
纹理2d:尖刺敌人;
矩形析取;
矩形sourceRect;
矩形小;
矩形小;
职业球员;
键盘状态键盘状态;
浮子过去了;
浮动延迟=90f;
int frameCount=0;
公共常数int屏幕高度=550;
public const int screenWidth=800;
公共游戏
{
graphics=新的GraphicsDeviceManager(此);
graphics.PreferredBackBufferHeight=屏幕高度;
graphics.PreferredBackBufferWidth=屏幕宽度;
Content.RootDirectory=“Content”;
}
///
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
///
受保护的覆盖无效初始化()
{
destRect=新矩形(100100,60,60);
destRectSmall=新矩形(100300,20,20);
base.Initialize();
}
///
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
///
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
coinCount=Content.Load(“coinCount”);
platformsList=新列表();
pickUpList=新列表();
//healthBarsList=新列表();
staticEnemyList=新列表();
coinAnim=Content.Load(“CoinSpinAnim”);
coinAnimBig=Content.Load(“CoinAnim”);
浮动平台=Content.Load(“平台1”);
地面平台=Content.Load(“地面平台1”);
redPlayer=Content.Load(“TestSprite”);
SpikeFounder=Content.Load(“Spike”);
//healthEmpty=Content.Load(“HealthBarEmpty”);
//health1=Content.Load(“HealthBar1”);
//health2=Content.Load(“HealthBar2”);
//health3=Content.Load(“HealthBar3”);
//health4=Content.Load(“HealthBar4”);
//health5=Content.Load(“HealthBar5”);
//health6=Content.Load(“HealthBar6”);
//health7=Content.Load(“HealthBar7”);
//health8=Content.Load(“HealthBar8”);
//health9=Content.Load(“HealthBar9”);
//healthFull=Content.Load(“HealthBarFull”);
//healthBarsList.Add(healthEmpty);
//healthBarsList.Add(health1);
//healthBarsList.Add(health2);
//healthBarsList.Add(health3);
//healthBarsList.Add(health4);
//healthBarsList.Add(health5);
//healthBarsList.Add(health6);
//healthBarsList.Add(health7);
//healthBarsList.Add(health8);
//healthBarsList.Add(health9);
//healthBarsList.Add(healthFull);
platformsList.Add(新PlatformSprite(地面平台,新矢量2(0454));
platformsList.Add(新的PlatformSprite(floatingPlatform,新的Vector2(500330));
platformsList.Add(新的PlatformSprite(floatingPlatform,新的Vector2(100290));
platformsList.Add(新的PlatformSprite(floatingPlatform,新的Vector2(300250));
platformsList.Add(新的PlatformSprite(floatingPlatform,新的Vector2(170250));