surface_set_target(surface_id);
参数 描述 surface_id 作为绘制目标的表面层的ID。
Boolean(布尔值)
With this function you set all further drawing to the target surface rather than the screen and in this way you can tell GameMaker Studio 2 to only draw specific things to the specified surface. 请注意如果完成之后没有调用 surface_reset_target ,接下来屏幕上什么都不会绘制(即使是其它实例),而是绘制到了表面上。还需要知道的是,还需要在实例的绘制事件中绘制才可以看到表面层的内容。You can check the return value of this function too as a debug tool to check whether the surface target was set or not, with a return value of 0 being a failure to set the target and any other positive value being a success.
One thing that should be noted is that surfaces are stacked so you cannot jump from target to target and then reset to the normal draw target at the end, but rather you must open and close rendering targets. For example, this will not work correctly:
surface_set_target(surf1);
draw_text(32, 32, "surface1");
surface_set_target(surf2);
draw_text(32, 64, "surface2");
surface_reset_target();
换之,你必须为每一个设置的表面重置目标,就像你必须在代码中使用打开和关闭的大括号{} 。所以,上面的应该这样写:
surface_set_target(surf1);
draw_text(32, 32, "surface1");
surface_reset_target();
surface_set_target(surf2);
draw_text(32, 64, "surface2");
surface_reset_target();
或者这样:
surface_set_target(surf1);
draw_text(32, 32, "surface1");
surface_set_target(surf2);
draw_text(32, 64, "surface2");
surface_reset_target();
surface_reset_target();
if view_current = 0
{
surface_set_target(surf);
with (obj_Effect)
{
draw_self();
}
surface_reset_target();
}
else
{
draw_surface(surf, 0, 0);
}
上述代码将检测当前是哪个视野在绘制,如果是view[0] ,它将设置绘制目标到一个表面层,并在表面层上绘制“obj_Effect”所有实例 ,然后重置绘制目标。如果当前视野不是 view[0],将表面层绘制到屏幕上。