我正在XNA中制作游戏,我注意到当我发布游戏时运行速度比在发布模式下运行时要快.我在构建选项中启用了优化,禁用了跟踪和调试.还有什么可以在这里发生.这导致调整困难.谁看过这个吗?会发生什么事?
我正在查看Xna Framework Game类的源代码,特别是它如何进行Draw调用,我可以在GraphicsDeviceManager.EndDraw()中看到对GraphicsDevice.Present()的调用,但我找不到对GraphicsDevice.BeginScene的调用()或GraphicsDevice.EndScene(),甚至不在GraphicsDevice类本身.任何人都知道他们如何处理这种情况
我一直在阅读有关如何在Silverlight应用程序中使用它的教程,但我需要在XNA中使用它.所有教程都引用了Microsoft.Xna.Framework.GamerServices包,但是没有这样的类......
我错了什么?
我使用Consolas字体来显示玩家得分.屏幕宽480,我希望它在中间.大小是24所以把它放在中间,不应该这样做:
string score ="9999"; 中= 480/2 - (score.Lenght*24)/ 2;
一些文本如何向左(大数字)或太多向右(低数字).
我虽然可以算一下这个,因为consolas是一个等宽字体?
我想在我的XNA游戏中实现一个简单的计数器.认为这很简单.我有以下代码:
    elapsed = gameTime.ElapsedGameTime.TotalMilliseconds;
        timer -= (int)elapsed;
        if (timer <= 0)
        {
            timer = 10;   //Reset Timer
        }
Run Code Online (Sandbox Code Playgroud)
但过去从未改变过0.0.我错过了一些明显的东西吗?我怀疑我.我将gameTime声明在顶部并像往常一样初始化.
如上所述,这里有更多代码:
公共类Game1:Microsoft.Xna.Framework.Game {
private GameTime zombieTime; 
    public Game1()
    {
        zombieTime = new GameTime();
        // Other (unrelated) stuff here
    }
    protected void AddZombie()
    {
        elapsed = zombieTime.ElapsedGameTime.TotalMilliseconds;
        timer -= (int)elapsed;
        if (timer <= 0)
        {
            timer = 10;   //Reset Timer
            Zombie zombie = new Zombie(ScreenWidth, ScreenHeight, random);
            zombie.LoadContent(this.Content, "ZombieSprites/ZombieLeft1");
            zombies.Insert(0, zombie);
        }
     }
    protected void Update()
    {
        AddZombie();
        // Other game update …Run Code Online (Sandbox Code Playgroud) 我有一小部分游戏,它基本上显示了一本书的页面.Update方法没有做任何事情,Draw方法如下:
public override void Draw(GameTime gameTime)
{
    SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    spriteBatch.Begin();
    spriteBatch.Draw(background.Image, background.Bounds, Color.White);
    spriteBatch.DrawString(font, name, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - font.MeasureString(name).X / 2, 100), Color.Black);
    spriteBatch.DrawString(font, currentPage.PageText, new Vector2(currentPage.TextArea.X, currentPage.TextArea.Y), Color.Black);
    if (currentPageNumber != 1)
    {
        spriteBatch.Draw(next.Image, previous.Bounds, null, Color.White, 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F);
    }
    if (currentPageNumber != noOfPages)
    {
        spriteBatch.Draw(next.Image, next.Bounds, Color.White);
    }
    DrawEmptyRectangle(spriteBatch, 3F, Color.Black, new Rectangle(back.Bounds.X - 1, back.Bounds.Y - 1, back.Bounds.Width + 1, back.Bounds.Height + 1));
    DrawEmptyRectangle(spriteBatch, 3F, Color.Black, new Rectangle(play.Bounds.X - 1, play.Bounds.Y …Run Code Online (Sandbox Code Playgroud) 我正在为我的游戏开展响应式设计.我根据屏幕尺寸重新计算对象的位置.我正在做好的计算,但我的函数给我错误的结果总是返回0.我需要返回值为Int.
这里的代码:
public int rdnW(int a)
{
    double b;
    b = (a / 800 * 100);
    return (int)(b * Widths / 100);
}
Run Code Online (Sandbox Code Playgroud)
有了断点,我看到b总是= 0; 在我的情况下a = 258.谢谢
所以,我有一个类GameObject,我用它作为许多子类的基础.
class GameObject()
{
    blah;
}
class AmmoBox() : Gameobject()
{
    different blah;
}
class Taco() : GameObject() {very different blah;}
Run Code Online (Sandbox Code Playgroud)
后来我在列表中使用它们,我想为每个子类指定不同的更新/ etc行为.
foreach (AmmoBox a in GameObjects) { }
foreach (Taco t in GameObjects) { }
Run Code Online (Sandbox Code Playgroud)
编译器抛出错误"无法将'GameObject'类型的对象强制转换为'AmmoBox'.我知道这是一个可怜的错误,我该怎么做呢?