Skip to content

九宫格(NineSlice) ​

Phaser Editor v5 · 英文原文

九弦是内置的 PhaserZ 对象类型: Phaser.GameObjects.NineSlice。该类型允许您显示一个既可以水平伸展,也可以垂直伸展,但保留固定大小角的纹理对象。

使用 nineSlice factory 创建一个 九切的代码。 这就是 scene compiler 生成 九切的代码的方法 :

javascript
const nineslice = this.add.nineslice(
                              0, 600, // x, y
                              "ui", "green-button", // texture, frame
                              300, 200, // width, height
                              70, 70, // leftWidth, rightWith
                              60, 60); // topHeight, bottomHeight

要在现场创建一个九切对象,你应该遵循这些步骤:

  • 将一个内置的九元立格块丢到现场:

    Drop a nine slice object to the scene

  • 选择对象的纹理, 按 X 键, 或在纹理部分打开纹理对话框 :

    Select textureThe result of selecting the texture

  • 更改对象大小。 在 Size section 中, 您可以设置对象的宽度和高度。 同时您也可以使用 Resize tool( 按 Z 键 ) :

    Resize the object

  • 在 ** 9ine 切片属性部分, 更改切片大小。 您还可以激活 Nine Slice tool, 并更改场景大小 :

    Edit the slice size.

顺便说一句,你可以convert an Image or Sprite or any other game object into a Nine Slice。

九块切片属性 ​

九切片类型与其他对象类型共享属性 :

但也有特殊属性:

Nine Slice properties.

3 个切片模式 ​

九晶体可以只用三个水平切片来创建。这是对只需要水平拉伸的对象的一种优化。如果将上和下高度设置为0,则该优化将启动。

在 Phaser 编辑器中, 我们提供一个 ** TreeSlice** 块来创建 九切对象的这个特定配置。 您可以将这个块降入创建对象的场景 :

Create a 3 slice object.

九切片对象处于三切片模式时,可以使用Slice Tool和三切片属性 部分更改切片的大小,注意只显示宽度属性和操纵器:

Changes the width of the slices.


社区翻译