我需要什么来为这个游戏创建这个控件? (如管道)

发布于 2024-11-30 18:31:03 字数 262 浏览 1 评论 0原文

这是我在本部分(XNA 和游戏开发)的第一篇文章。我正在尝试获取下图所示的东西。正如您所看到的,有一条高速公路,在高速公路内部,会有一些物体在移动(毫秒)。我猜街头行为就像一条管道。当高速公路装载一个物体时,它会出现在起点,并且会穿过高速公路,直到到达高速公路的另一个极端。

我的主要问题是,如何才能仅在高速公路内移动多个物体?

在此处输入图像描述

提前致谢。

This is my first post at this section (XNA and game development). I'm trying to get something the below image. As you can see, there's a highway and inside of it, there'll be some objects moving (millisecond). I guess the streeth behavier is like a pipeline. When the highway loads an object, it appears at the beggining and it'll be moving through the highware until it arrives in the another extreme of the highway.

My main problem is, how can I do to move several objects only inside of the highway?

enter image description here

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2024-12-07 18:31:03

您需要一个点列表和一个精灵列表

class Path 
{
   List<Vector2> Points;
   float[] Lengths;
   Vector2[] Directions;

   void Build()
   {
       Lengths = new float[Points.Count-1];
       Directions = new float[Points.Count-1];
       for (int i=0; i<Points.Count-1;i++)
       {
            Directions[i] = Points[i+1] - Points[i];
            Lengths[i] = Directions[i].Length();
            Directions[i].Normalize();
       }  
   }
}

class Sprite 
{
     Vector2 Position;
     float StagePos;
     int StageIndex;
     Path Path;
     float Speed;

     void Update(float Seconds)
     {
         if (StageIndex!=Path.Points.Count-1)
         {
             StagePos += Speed * Seconds;
             while (StagePos>Path.Lengths[StageIndex])
             {
                 StagePos -= Path.Lengths[StageIndex]; 
                 StageIndex++;              
                 if (StageIndex == Path.Points.Count-1) 
                 {
                     Position = Path.Points[StageIndex];
                     return;
                 }
             }
             Position = Path.Points[StageIndex] + Directions[StageIndex] * StagePos;
         }
     }    
}

You need a list of points and a list of sprites

class Path 
{
   List<Vector2> Points;
   float[] Lengths;
   Vector2[] Directions;

   void Build()
   {
       Lengths = new float[Points.Count-1];
       Directions = new float[Points.Count-1];
       for (int i=0; i<Points.Count-1;i++)
       {
            Directions[i] = Points[i+1] - Points[i];
            Lengths[i] = Directions[i].Length();
            Directions[i].Normalize();
       }  
   }
}

class Sprite 
{
     Vector2 Position;
     float StagePos;
     int StageIndex;
     Path Path;
     float Speed;

     void Update(float Seconds)
     {
         if (StageIndex!=Path.Points.Count-1)
         {
             StagePos += Speed * Seconds;
             while (StagePos>Path.Lengths[StageIndex])
             {
                 StagePos -= Path.Lengths[StageIndex]; 
                 StageIndex++;              
                 if (StageIndex == Path.Points.Count-1) 
                 {
                     Position = Path.Points[StageIndex];
                     return;
                 }
             }
             Position = Path.Points[StageIndex] + Directions[StageIndex] * StagePos;
         }
     }    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文