Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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
Libgdx 如何创建基本多边形?_Libgdx_Collision Detection_Overlap_Polygons - Fatal编程技术网

Libgdx 如何创建基本多边形?

Libgdx 如何创建基本多边形?,libgdx,collision-detection,overlap,polygons,Libgdx,Collision Detection,Overlap,Polygons,我想创建一个多边形,它将使用overlapse与矩形碰撞。我唯一的问题是我不知道如何创建多边形,我的意思是只创建多边形。每次我试图在互联网上找到它,我都会发现有史以来最复杂的代码。所以,如果你能告诉我如何创建一个多边形,并解释如何声明它的形状,我将不胜感激 多边形大致如下所示: 注意:它应该是对称的,但我不确定我是否绘制了对称的…根据多边形类上的,您可以简单地使用它的构造函数定义一个新多边形。例如: //we want to create a simple square shaped polyg

我想创建一个多边形,它将使用overlapse与矩形碰撞。我唯一的问题是我不知道如何创建多边形,我的意思是只创建多边形。每次我试图在互联网上找到它,我都会发现有史以来最复杂的代码。所以,如果你能告诉我如何创建一个多边形,并解释如何声明它的形状,我将不胜感激

多边形大致如下所示:

注意:它应该是对称的,但我不确定我是否绘制了对称的…

根据多边形类上的,您可以简单地使用它的构造函数定义一个新多边形。例如:

//we want to create a simple square shaped polygon
//we create an array to hold every vertex we need, there are 4 vertices
//this constructor uses 1 float array as parameter, where every two element define the position of 1 vertex
polygon = new Polygon(new float[]{ //so we pass a new float array to the constructor
                      0,0, //this is the x,y of the first vertex
                      width,0, //the second vertex
                      width,height, //the third
                      0,height}); //and the last
这是一个简单的示例,但您应该能够了解如何展开形状。我将再举一个例子,添加一个额外的顶点来创建房屋形状:

polygon = new Polygon(new float[]{ //so we pass a new float array to the constructor
                      0,0, //this is the x,y of the first vertex
                      width,0, //the second vertex
                      width,height, //the third
                      (width*0.5),(height*1.5), //this one is now extra, it adds one vertex between the last and the one before it
                      0,height}); //and the last

如果您需要更多信息,请告诉我。

您认为多边形是什么意思?任何非圆形的形状,如果您这样问,我想我会发现我完全是个哑巴。好吧,您没有错。但在编程中,我们通常处理三角形。。。我不知道libgdx在碰撞检测方面提供了什么,但是对于您提供的形状,您需要非常复杂的数学来检测碰撞。实际上,我可以声明一个多边形和一个矩形,然后执行ifRect.overlapsePoly{真的吗?这实际上很好,我可能需要看一下那个库:Psorry,因为我的反应太晚了,但非常感谢。我完全理解,但有没有办法测试多边形?看看它是否是我想要的形状?我的意思是,如果你能暂时想象它