Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#Monogame/XNA在快速移动的同时保持纹理粘在一起_C#_Object_Xna_Textures_Monogame - Fatal编程技术网

c#Monogame/XNA在快速移动的同时保持纹理粘在一起

c#Monogame/XNA在快速移动的同时保持纹理粘在一起,c#,object,xna,textures,monogame,C#,Object,Xna,Textures,Monogame,目前,我试图用C#编写一个2D轮盘赌,使用Monogame作为框架。 我对Monogame很有经验,但我从来没有管理过快速移动的纹理来粘在一起 其思想是,3种纹理(黑色、红色、绿色)在一行15个对象中相互连接。 这很好,只要我不开始滚动所有这些对象来实际“使轮子移动” 移动一段时间后,纹理不再相互连接。它们之间有一些空间或开始重叠。 我制作了一个简短的视频来澄清这个问题:(大约10MB,一些浏览器可能在它出现之前就已经下载了) 这是最重要的代码: const int _roulleteOffse

目前,我试图用C#编写一个2D轮盘赌,使用Monogame作为框架。 我对Monogame很有经验,但我从来没有管理过快速移动的纹理来粘在一起

其思想是,3种纹理(黑色、红色、绿色)在一行15个对象中相互连接。 这很好,只要我不开始滚动所有这些对象来实际“使轮子移动”

移动一段时间后,纹理不再相互连接。它们之间有一些空间或开始重叠。 我制作了一个简短的视频来澄清这个问题:(大约10MB,一些浏览器可能在它出现之前就已经下载了)

这是最重要的代码:

const int _roulleteOffset = 170; // X coordinate to start at
Sprite[] fieldList = new Sprite[15]; // Represents my wheel (Array of my roulette fields/textures)
Rectangle scrollArea; // Fixed Area for the complete fieldList
float scrollSpeed = 0.0f; // Scrollspeed of the wheel. 0 on start.

// First I call the Content.Load to fill fieldList.Texture then
// this is called to position the "wheel" objects
private void AdditionalInit()
{
    for (int i = 0; i < fieldList.Length; i++)
    {
        fieldList[i].Position = new Vector2(_roulleteOffset + i * fieldList[i].Texture.Width, Statics.GAME_WINDOW_HEIGHT / 2 - fieldList[i].Texture.Height / 2); 
    }
    scrollArea = new Rectangle((int)fieldList[0].Position.X, (int)fieldList[0].Position.Y, fieldList[0].Texture.Height * fieldList.Length + 30, fieldList[0].Texture.Height);
}

// This Method is called in Update() - And I guess the problem has to be fixed here
private void ScrollRoulette()
{
    for (int i = 0; i < fieldList.Length; i++)
    {
        fieldList[i].position.X += scrollSpeed; // scrollSpeed is set with pressing + or - on keyboard
        if (fieldList[i].Position.X >= scrollArea.Width + fieldList[i].Texture.Width)
        {
            // After leaving the "scrollArea" set it to the start of it (Leaving on right side and entering at the left side again)
            fieldList[i].position.X = scrollArea.X - fieldList[i].Texture.Width;
        }
    }
}

// The part of my Draw Method. But I don't think that I made a mistake here
public override void Draw(GameTime gameTime)
{
    Statics.SPRITEBATCH.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
    for (int i = 0; i < fieldList.Length; i++)
    {
        Statics.SPRITEBATCH.Draw(fieldList[i].Texture, fieldList[i].Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
    }
    Statics.SPRITEBATCH.End();
}
const int\u roulleteOffset=170;//从X坐标开始
精灵[]字段列表=新精灵[15];//表示我的控制盘(轮盘赌场/纹理的数组)
矩形滚动区域;//完整字段列表的固定区域
浮动滚动速度=0.0f;//滚轮的滚动速度。开始时为0。
//首先我调用Content.Load来填充fieldList.Texture然后
//这是用来定位“轮子”对象的
私有void AdditionalInit()
{
for(int i=0;i=scrollArea.Width+fieldList[i].Texture.Width)
{
//离开“scrollArea”后,将其设置为其开头(从右侧离开,然后再次从左侧进入)
fieldList[i].position.X=scrollArea.X-fieldList[i].Texture.Width;
}
}
}
//我画法的一部分。但我不认为我犯了错误
公共覆盖无效绘制(游戏时间游戏时间)
{
Statics.SPRITEBATCH.Begin(SpriteSortMode.BackToFront,BlendState.AlphaBlend);
for(int i=0;i

只要看视频就能明白我在说什么。也许你能帮我。即使速度较慢,纹理也会随着时间的推移开始断开或重叠。

在另一个德国论坛的帮助下,我解决了这个问题!感谢上帝。这一行花了我一整天的时间。我只需要调整传入磁贴的位置。不仅仅是将pos.x设置为起始位置

    private void ScrollRoulette()
    {
        for (int i = 0; i < fieldList.Length; i++)
        {
            fieldList[i].position.X += scrollSpeed;

            if (fieldList[i].Position.X >= scrollArea.Width + (fieldList[i].Texture.Width * 2))
            {
                // This works now
                fieldList[i].position.X = scrollArea.X + (fieldList[i].Position.X - (scrollArea.Width + scrollArea.X) );
            }                
        }
    }
private void scrollRoulete()
{
for(int i=0;i=scrollArea.Width+(字段列表[i].Texture.Width*2))
{
//现在可以了
fieldList[i].position.X=scrollArea.X+(fieldList[i].position.X-(scrollArea.Width+scrollArea.X));
}                
}
}

当您从一开始就将scrollSpeed设置为一个常量(如10),然后直接将其停止为0时,这种效果还会发生吗?如果不会,我认为问题在于fieldList[I].Position.X和scrollArea.Width+fieldList[I].Texture.Width之间的差异(在ScrollRoulette方法中的条件下)对于每个字段都会有所不同,当您在下一行设置它时,将此差异添加到位置可能会有所帮助。这有助于找到解决方案,但不是解决方案。如果我将速度设置为10,它只会创建一个小间隙,如~10像素宽。但是,当滚动该常量值10时,它看起来很好。一旦我降低或提高速度,最终会再次产生更多的间隙或重叠。这是间隙,其余的在滚动大约一分钟后看起来很好。在滚动时将速度设置为较低后看起来是这样的。将滚动速度作为条件中的第二行添加到位置也没有什么奇怪的行为。为了确保,您可以尝试用此替换设置的位置行吗?字段列表[i].位置.X=scrollArea.X+scrollArea.Width-fieldList[i].位置.X;