可以使用sprite_nineslice_create()创建九宫格结构,或使用sprite_get_nineslice()从sprite中检索。 此结构将包含可以使用sprite_set_nineslice()更改并应用于 sprite 的属性。
如果从精灵中检索,更改此结构中的值将影响原始精灵。
此结构中将提供以下属性:
九宫格结构 | ||
---|---|---|
变量 | 类型 | 描述 |
enabled | Boolean | 如果为子程序启用了九宫格,则此布尔将为true,如果已禁用false。可以修改此选项以启用或禁用 sprite 的九宫格。 |
left | Real | 这是 x 轴上左导向相对于精灵左边缘的偏移。 |
right | Real | 这是 x 轴上相对于精灵右边缘的右导向的偏移。 |
top | Real | 这是 y 轴上相对于精灵顶边的顶部导向的偏移。 |
bottom | Real | 这是 y 轴上底部导向相对于精灵底部边缘的偏移。 |
tilemode | Array of 图块模式常量s | 这将返回包含边和中心图块的图块模式的数组。 |
可使用以下常量作为数组索引读取或修改每个图块的图块模式:
九宫格边缘常量 | |
---|---|
常量 | 描述 |
nineslice_left | The left edge slice |
nineslice_top | The top edge slice |
nineslice_right | The right edge slice |
nineslice_bottom | The bottom edge slice |
nineslice_centre | The centre slice |
图块的图块模式将是(或可以设置为)以下常量之一:
图块模式常量 | |
---|---|
常量 | 描述 |
nineslice_stretch | The slice will be stretched |
nineslice_repeat | The slice will be repeated |
nineslice_mirror | The slice will be repeated by mirroring |
nineslice_blank | The slice will not be stretched or repeated, resulting in a blank area after it |
nineslice_hide | The slice will not appear at all |
由于图块模式是数组,您需要使用数组语法来更改图块的"图块模式"。下面的代码示例将顶部图块的图块模式设置为重复:
var _nineslice = sprite_get_nineslice(spr_box);
_nineslice.tilemode[nineslice_top] = nineslice_repeat;
有关九宫格技术的更多信息,请参阅本页。