English 中文(简体)
XNA的堆积背景
原标题:Scrolling background flicker in XNA

我正在利用Xnadevelopment.com(经修改以符合我的要求)的背景理论,为窗口电话游戏创造一个垂直的滚动路。 纵观下的形象,这种背景似乎正在动摇。 尽管我正在使用单一图像,但即便使用了多种图像,也会出现浮雕。 我播放了一部显示屏幕顶端的浮标的你管录像。

http://youtu.be/Ajdiw2zILq0 Below is the code used to create the loop:

http://www.ohchr.org。

    private List<string> _road;
    private VericalBackgroundLoop _roadLoop;
    private readonly Vector2 _roadSpeed = new Vector2(0, 300);

    public void LoadContent(ContentManager contentManager)
    {
        _road = new List<string>
                         {
                             "Test\Road_Bgnd",
                             "Test\Road_Bgnd"
                         };

        _roadLoop = new VericalBackgroundLoop();
        _roadLoop.Initialize(_road, contentManager, Vector2.Zero, true);
    } 

    public void Update(TimeSpan elapsedTime)
    {
        _roadLoop.Update(_roadSpeed, elapsedTime);
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        _roadLoop.Draw(spriteBatch);
    }

<<>Background loop>:

    private List<Sprite> _sprites;
    private bool _isLoopDirectionTopToBottom;
    private Vector2 _loopDirection;

    public void Initialize(List<string> spriteNames, ContentManager contentManager, Vector2 loopStartPosition, bool isLoopDirectionTopToBottom)
    {
        _sprites = new List<Sprite>();
        _isLoopDirectionTopToBottom = isLoopDirectionTopToBottom;

        _loopDirection = new Vector2(0, -1);

        // Build the sprite object s list
        foreach (string spriteName in spriteNames)
        {
            Sprite sprite = new Sprite();
            sprite.LoadContent(contentManager, spriteName);

            _sprites.Add(sprite);
        }

        if (_isLoopDirectionTopToBottom)
        {
            // Set the initial position for the sprite objects
            foreach (Sprite currentSprite in _sprites)
            {
                if (currentSprite == _sprites.First())
                {
                    currentSprite.Position = loopStartPosition;
                }
                else
                {
                    Sprite prevSprite = GetSpriteAtIndex(_sprites.IndexOf(currentSprite) - 1);
                    currentSprite.Position = new Vector2(0, prevSprite.Position.Y - prevSprite.Size.Height);
                }
            }
        }
     }

    public void Update(Vector2 loopSpeed, TimeSpan elapsedTime)
    {
        if (_isLoopDirectionTopToBottom)
        {
            foreach (Sprite currentSprite in _sprites)
            {
                if (currentSprite == _sprites.First())
                {
                    Sprite lastSprite = _sprites.Last();
                    if (currentSprite.Position.Y > (currentSprite.Size.Height))
                    {
                        currentSprite.Position.Y = lastSprite.Position.Y - lastSprite.Size.Height;
                    }
                }
                else
                {
                    Sprite prevSprite = GetSpriteAtIndex(_sprites.IndexOf(currentSprite) - 1);
                    if (currentSprite.Position.Y > (currentSprite.Size.Height))
                    {
                        currentSprite.Position.Y = prevSprite.Position.Y - prevSprite.Size.Height;
                    }
                }

                // Update the sprite X position with the speed and time
                currentSprite.Position -= _loopDirection * loopSpeed * (float)elapsedTime.TotalSeconds;
            }
        }
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        foreach (Sprite sprite in _sprites)
        {
            sprite.Draw(spriteBatch);
        }
    }

    private Sprite GetSpriteAtIndex(int index)
    {
        return _sprites[index];
    }

我需要帮助弄清为什么出现浮筒,为什么动议似乎jer不平(这在装置上是比好的,但还是“妇女”。 IsFixedtime 在游戏中,步骤是正确的。 谢谢。

http://www.un.org。 如果使用3个或3个以上图像,就不出现象浮体这样的种子。 这可能是由于第一种形象没有被迅速重新纳入开办职位。 但是,仍在试图 figure灭 the,ation死仍然如此之大:

问题回答

我首先要报告看到浮雕或utter。 在“评估湖”论坛上抽出一些员额。 (glad You reFinding luck using my tutorial/samples by the way!)

http://forums.create.msdn.com/forums/t/30500.aspx”rel=“nofollow” http://forums.create.msdn.com/forums/t/30500.aspx

And here s the best answer I ve seen to date from one of the XNA Framework developers -> http://forums.create.msdn.com/forums/p/9934/53561.aspx#53561

从根本上说,你 st倒了“a”解决办法,但正如肖恩的言辞指出,解决问题有多种办法,这只是取决于你们的游戏权。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签