表面层


在一般的绘制事件里, GameMaker Studio 2 不会真实的绘制屏幕上,而是绘制到 表面上,那个表面叫做应用表面。This surface is basically a blank "canvas" that can then later be manipulated before being drawn to the screen when needed, and in most cases GameMaker Studio 2 handles this for you (although you can also manipulate it yourself in code for shaders, scaling and many other things - further details are given below).

此外,除了应用表面,也可以创建自己的表面层,游戏中用来设计一些华丽的特效。例如,你可以使用表面来“捕捉”实例,然后摧毁它,并以这种方式,在表面(surfaces)上,实例的精灵显示的位置,创建一个贴花效果,就好像它仍然存在一样,以此来制作一些图像效果,如碎片,血液等.. 这上面没有任何真实的处理进程。另外就是使用表面作为需要操作的纹理贴图,或者创建“在飞”的精灵,或者创建复杂的叠加。in fact, the uses for surfaces are endless!

表面使用很简单,但在使用的时候,也有几个应遵循的基本规则:

表面层的基本用法如下 - 首先创建一个表面,给它的索引分配给一个变量。然后你可以设置绘图目标到表面上,而不是显示器,往里面绘制内容并进行一些调整。一旦完成,重置绘制目标,再让进一步的绘制发生在屏幕上。One thing to note is that should you require drawing the whole display to a surface (including tiles, backgrounds etc...) you can simply access the application surface itself (see below for further details) or you could assign a surface to a view port using the variable view_surface_id[0..7] as with this all that is visible in that view port will be drawn to the corresponding surface.

The following functions exist to deal with surfaces (these functions are specific for creating and manipulating surfaces, but to actually draw them to the screen you should be using the specific draw functions that can be found in the section on Surface Drawing, below):


正如上面提过的,所有普通绘制都是在应用表面层里进行的,这个表面可以像通常的表面层一样改变或控制。However, it is not a normal surface and advanced users will find that it enables complete control over how and when things are drawn in GameMaker Studio 2. 更多具体的内容,以及一些特性函数,请查阅如下的章节:

  1. 应用表面层

The following functions and variable exists for referencing the application surface:

And you also have a few special functions that are designed only for use with the application surface:


Surfaces are an incredibly powerful graphic tool that GameMaker Studio 2 provides you for creating special effects and a whole host of other things. They are relatively simple to use as they are basically a canvas that you draw to instead of the display screen, and this canvas can then be manipulated and changed before being drawn with the functions in this section.

注:由于储存在显存里,表面层运行时存在随时停止并退出的可能性。在直接引用它们之前,你需要 一直使用 surface_exists检测表面层是否退出。

The following functions exist for drawing surfaces:

  1. draw_surface
  2. draw_surface_ext
  3. draw_surface_part
  4. draw_surface_part_ext
  5. draw_surface_stretched
  6. draw_surface_stretched_ext
  7. draw_surface_tiled
  8. draw_surface_tiled_ext
  9. draw_surface_general