draw_primitive_begin

必须先调用此函数,然后才能定义任何基元。有6种类型的基元可以定义为以下常量:

基元类型常量
常量描述
pr_pointlistA point list - A point is drawn for every vertex.
pr_linelistA line list - A line is drawn between the first and the second vertex, between the third and fourth vertex, etc.
pr_linestripA line strip - A line is drawn between the first and the second vertex, between the second and the third vertex, the third and the fourth vertex, etc.
pr_trianglelistA triangle list - A triangle is drawn for the first, second and third vertex, then for the fourth, fifth and sixth vertex, etc.
pr_trianglestripA triangle strip - A triangle is drawn for the first, second and third vertex, then for the second, third and fourth vertex, etc.
pr_trianglefanA triangle fan - Every two vertices connect to the first vertex to make a triangle.

WARNING This primitive type is not natively supported on some platforms and there could be a performance hit if you use it.

下图基本上说明了它们的外观以及定义顶点的顺序:

The different primitive types

注意 在某些平台 (Windows、Xbox) 上,pr_trianglefan 类型本身不受支持,因此 GameMaker 在编译游戏时会进行转换以使它们正常运行。这意味着在这些平台上,pr_trianglefan 类型的使用速度将比其他类型慢得多。

警告 除非您在 游戏选项 中启用了 WebGL,否则这些函数无法与 HTML5 模块配合使用。

 

语法:

draw_primitive_begin(kind);

参数类型描述
kind基元类型常量你要绘制的基元类型。

 

返回:

N/A

 

例子:

var _steps = 20;
var _xx = 50;
var _yy = 50;
var _radius = 30;
draw_primitive_begin(pr_trianglefan);
draw_vertex(_xx, _yy);
for(var i = 0; i <= _steps; ++i;)
{
    draw_vertex(_xx + lengthdir_x(_radius, 270 * i / _steps), _yy + lengthdir_y(_radius, 270 * i / _steps));
}
draw_primitive_end();

上述代码将绘制由基元组成的圆的四分之三。