surface_create


语法:

surface_create(w, h);

参数 描述
w 创建的表面层的宽度。
h 创建的表面层的高度。


Returns:

实数


描述

这个函数被用来创建一个表面层,而且将会返回这个表面的索引地址,这个索引应该储存在一个变量上,将来可以调用它。When the surface is first created, it may contain "noise" as basically it is just an area of memory that is put aside for the purpose (and that memory may still contain information), so you may want to clear the surface before use with a function like draw_clear_alpha.

强烈建议所有创建的表面层大小设置为2的N次方,比如16、128、512、1024像素。This is not exactly necessary on certain platforms (like Windows and MacOS) but it will certainly increase compatibility on those targets, while for HTML5 and devices it is essential and very it's important that you remember this or you may run into problems later.


例如:

if !surface_exists(surf)
   {
   surf = surface_create(1024, 1024);
   surface_set_target(surf);
   draw_clear_alpha(c_black, 0);
   surface_reset_target();
   view_surface_id[0] = surf;
   }

上述代码将检测是否存在一个表面层,如果没有则创建一个1024×1024px大小的表面层,并指定给索引为变量“surf”。然后绘制目标设置给这个新的表面层,接下来是清除表面,设置为透明,再是将绘制目标设置给显示器。最后,给这个表面层指定给一个视野。