绘制和创建图元


A primitive is a type of drawing done using points to define what is shown on the screen. They can be made up of single points, lines, or triangles and can be coloured, have alpha blending and even be given a texture, which means that they can be used to create some very exciting effects in a 2D game! For example, you can create a rectangle using multiple triangle primitives, then texture it with a flag sprite and in the draw event of an instance have that flag "wave" in the wind and distort the sprite you used by simply modifying the points that form the primitive.

WARNING! These functions do not work with the HTML5 module unless you have enabled OpenGL in the Game Options.

GameMaker Studio 2 permits you to define your own Vertex Formats from which you can create your own custom primitives. This can greatly speed up shader operations or can be used to extend their capabilities and create surprising effects. You can find information on this in the following sections:

IMPORTANT! Once you have created your vertex format, the order in which you have defined the vertex properties must be honoured when building your primitives. So, if you have defined a vertex format as position, colour, texture coordinate, then you must add these properties to the primitive in the same order otherwise you will get an error.


For an overview of how to create vertex formats using the above functions, see:

  1. Vertex Formats

Once you have created your vertex format (see the section above) you can then use it to build the primitives that you want to draw using the following functions:

IMPORTANT! The primitives that you build should follow the format that you have set using the Vertex Format functions, so if you have defined a vertex format with only positional data, there is no point building your primitive with colour data. You should note that the order in which you add properties to the primitive you are building is defined by the order in which you added these properties when creating the vertex format, so if you have defined the vector format with the order position, colour and texture coordinate, you must add these properties to the primitive being built in the same order otherwise you will get errors.


For an overview of how to build primitives using the vertex functions, see:

  1. Primitive Building