首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >XNA建设后未启动游戏项目

XNA建设后未启动游戏项目
EN

Stack Overflow用户
提问于 2014-02-10 20:14:16
回答 1查看 120关注 0票数 0

我是XNA游戏开发的新手,目前正在练习制作游戏。

我从创建一个简单的平台开始,慢慢地建立起游戏和游戏功能的逻辑。我最近的增加似乎破坏了这个项目。它是在添加了一个健康条函数之后开始的,其中我添加了11个纹理(健康栏为空,健康条为1/10,健康条为2/10等等)。

当玩家遇到一个有害的对象,比如游戏中的一个尖峰,显示给生命栏的纹理会改变(所以如果生命栏是9,纹理就会改变为healthBar8)。

该问题最初是由于在两个不同的Visual窗口中打开两个相同的项目而导致的阻止项目生成的实际错误。(这太愚蠢了,我在谷歌上搜索了一下如何修复给定的错误,然后才发现我打开了两个窗口)。建议的解决方法是在预构建命令行框中输入这两行:

如果存在"$(TargetPath).locked“del "$(TargetPath).locked”如果存在"$(TargetPath)“如果不存在"$(TargetPath).locked”移动"$(TargetPath)“"$(TargetPath).locked”

这似乎修复了错误,但现在我的项目只构建而不启动,所以我关闭了我发现已经打开的额外窗口,并从预构建命令行框中删除了这两行,但是现在该项目只是构建而不启动。

我尝试创建一个新项目,并检查它是否构建了(它确实构建了,因此Visual本身并不是问题所在),然后复制并粘贴已损坏的项目的代码到这个新项目中,这个新项目仍然没有启动。

我不知道是什么导致了这一切,这是非常恼人的。如果我的问题表述得很糟糕,我真的很抱歉,因为这是我的第一个堆栈溢出问题(因为我从来没有感觉到有必要在网上发布问题),但是在大量的poorly搜索之后我找不到解决方案。

代码语言:javascript
运行
复制
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);
    }
}

正如你所看到的,我已经注释掉了所有的健康条形码,我希望这增加了我的问题的细节,但真的很抱歉,如果这是一个可怕的问题,我只是不知道做什么或从哪里开始修复它。

临时更新-固定资讯科技d

我把它缩小到了一个this循环,从而导致了这个“构建而不是启动”错误。我试过几次评论循环,然后再把它放回到桌面上,每次我评论它的时候,它都成功地启动了游戏。我的电话是正确的,所以我很抱歉没有引用确切的循环,但它是一个while循环,类似于: int j :0;while (j < staticEnemyList.Count) { if(player.enclosedRectangle.Intersects (staticEnemyListi.GetRectangle)) {playerHealth- j++ }

我认为这与将敌人列表索引设置为'i‘而不是j有关,但这并没有返回一个错误,因为在这个基础上,我在一个名为'i’的整数上有一个循环。仍然不知道为什么这个循环破坏了视频工作室,有什么建议会很酷吗?再次,我很抱歉,我的糟糕的格式等,当我在我的计算机上,我将更新与实际的时间循环代码。谢谢大家的评论,好建议-再一次.对不起--很难在电话上发表评论,我在8小时内无法回复,这只是暂时的:)

EN

回答 1

Stack Overflow用户

发布于 2014-09-19 14:58:26

该项目构建但没有出现,因为我错误地创建了一个愚蠢的无限时间循环。这是通过创建两个不同的整数而不是使用正确的整数及其对应的while循环来实现的。一个简单的问题真的很容易解决,但是对于刚接触C#的人来说,这看起来确实很吓人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21687002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档