Skip to content

Polygon ​

Phaser v4.1.0 · 英文原文

多边形形状是游戏对象, 可以添加到游戏、 组合或容器中。 您可以把它当作游戏中的其他对象, 如进行曲折、 缩放或允许输入或物理。 它为您提供了快速和简单的方式, 可以在游戏中不使用纹理来渲染此形状, 同时仍然利用在 WebGL 中被完整批量 。

此形状支持设置填充颜色和描边颜色。

多边形形状是通过提供点列表创建的,然后用来创建内部的多边形几何对象。这些点可以从多种格式设置:

  • 包含对数值的字符串, 由单个空格分隔: '40 0 40 20 100 20 100 80 40 80 40 100 0 50'

  • 点或矢量2对象阵列: [new Phaser.Math.Vector2(x1, y1), ...]

  • 具有公共 x/y 属性的天体阵列: [obj1, obj2, ...]

  • 代表点坐标的对数组: [x1,y1, x2,y2, ...]

  • 一组阵列,其中两个元素代表x/y坐标:[[x1, y1], [x2, y2], ...]

默认情况下,此形状的x和y坐标是指其中心,但视所提供的点的坐标而定,最终形状可能会被其来源抵消.

注意: 如果多边形中的任何点为负值, 方法 getBoundsz 将返回不正确的边框。 如果是, 请使用函数 Phaser.Geom.Polygon.GetAABB(polygon.geom) , 然后对返回的矩形位置进行相应调整 。

构造函数

new Polygon(scene, [x], [y], [points], [fillColor], [fillAlpha])

参数

名称类型可选默认值说明
scenePhaser.Scene否此游戏对象所属的景点。 一个游戏对象只能一次属于一个景点 。
xnumber是0这个游戏对象在世界的横向位置.
ynumber是0此游戏对象在世界的垂直位置 。
pointsany是构成多边形的点.
fillColornumber是多边形的颜色会填充,即0xff000为红色.
fillAlphanumber是多边形的α将被填充。 您也可以使用它的 alpha 属性设置整个形状的α 。

作用域: static

继承

Phaser.GameObjects.Shape

源码:src/gameobjects/shape/polygon/Polygon.js#L15
引入版本:3.13.0

继承的方法 ​

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape:


公开方法 ​

setTo ​

<instance> setTo([points]) ​

说明:

将这个多边形设定为给定点。

可以从多种格式设定点数:

  • 包含对数值的字符串, 由单个空格分隔: '40 0 40 20 100 20 100 80 40 80 40 100 0 50'

  • 点或矢量2对象阵列: [new Phaser.Math.Vector2(x1, y1), ...]

  • 具有公共 x/y 属性的天体阵列: [obj1, obj2, ...]

  • 代表点坐标的对数组: [x1,y1, x2,y2, ...]

  • 一组阵列,其中两个元素代表x/y坐标:[[x1, y1], [x2, y2], ...]

调用此方法将重置此形状的大小( 宽度, 高度) 和显示来源 。

它在给定的点上还运行着GetABB和EarCut,所以请注意不要在高频下进行,或者用太多的点来进行.

参数:

名称类型可选说明
pointsstring | Array.<number>Array.<Phaser.Types.Math.Vector2Like>是

返回值: Phaser.GameObjects.Polygon - 此游戏对象实例 。

源码:src/gameobjects/shape/polygon/Polygon.js#L108
引入版本:3.60.0


smooth ​

<instance> smooth([iterations]) ​

说明:

将多边形比指定的迭代数平滑。 基础多边形数据将被更新, 并替换为平滑值。 此调用可以被链条化 。

参数:

名称类型可选默认值说明
iterationsnumber是1应用多边形平滑的次数 。

返回值: Phaser.GameObjects.Polygon - 此游戏对象实例 。

源码:src/gameobjects/shape/polygon/Polygon.js#L84
引入版本:3.13.0


继承的成员 ​

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape:



社区翻译