九宫格结构

可以使用sprite_nineslice_create()创建九宫格结构,或使用sprite_get_nineslice()从sprite中检索。 此结构将包含可以使用sprite_set_nineslice()更改并应用于 sprite 的属性。

如果从精灵中检索,更改此结构中的值将影响原始精灵。

此结构中将提供以下属性:

九宫格结构
变量类型描述
enabledBoolean如果为子程序启用了九宫格,则此布尔将为true,如果已禁用false。可以修改此选项以启用或禁用 sprite 的九宫格
leftReal这是 x 轴上左导向相对于精灵左边缘的偏移。
rightReal这是 x 轴上相对于精灵右边缘的右导向的偏移。
topReal这是 y 轴上相对于精灵顶边的顶部导向的偏移。
bottomReal这是 y 轴上底部导向相对于精灵底部边缘的偏移。
tilemodeArray of 图块模式常量s这将返回包含边和中心图块的图块模式数组

 

图块模式

可使用以下常量作为数组索引读取或修改每个图块的图块模式

九宫格边缘常量
常量描述
nineslice_leftThe left edge slice
nineslice_topThe top edge slice
nineslice_rightThe right edge slice
nineslice_bottomThe bottom edge slice
nineslice_centreThe centre slice

图块的图块模式将是(或可以设置为)以下常量之一:

图块模式常量
常量描述
nineslice_stretchThe slice will be stretched
nineslice_repeatThe slice will be repeated
nineslice_mirrorThe slice will be repeated by mirroring
nineslice_blankThe slice will not be stretched or repeated, resulting in a blank area after it
nineslice_hideThe slice will not appear at all

由于图块模式是数组,您需要使用数组语法来更改图块的"图块模式"。下面的代码示例将顶部图块的图块模式设置为重复

例子:

var _nineslice = sprite_get_nineslice(spr_box);

_nineslice.tilemode[nineslice_top] = nineslice_repeat;

有关九宫格技术的更多信息,请参阅本页