代码拉取完成,页面将自动刷新
# BodyDef
**Description:**
  A record to describe the properties of a physics body.
**Class Object:** [BodyDef Class](/docs/api/Class%20Object/BodyDef).
**Inherits from:** [Object](/docs/api/Class/Object).
## BodyDef.BodyType
**Type:** Enumeration.
**Description:**
  An enumeration for the different types of bodies.
**Signature:**
```tl
enum BodyType
-- A body that does not move.
"Static"
-- A body that can move and be affected by forces.
"Dynamic"
-- A body that can move but is not affected by forces.
"Kinematic"
end
```
## type
**Type:** Field.
**Description:**
  Define for the type of the body.
**Signature:**
```tl
type: BodyType
```
## position
**Type:** Field.
**Description:**
  Define for the position of the body.
**Signature:**
```tl
position: Vec2
```
## angle
**Type:** Field.
**Description:**
  Define for the angle of the body.
**Signature:**
```tl
angle: number
```
## face
**Type:** Field.
**Description:**
  Define for the face image or other items accepted by creating `Face` for the body.
**Signature:**
```tl
face: string
```
## facePos
**Type:** Field.
**Description:**
  Define for the face position of the body.
**Signature:**
```tl
facePos: Vec2
```
## linearDamping
**Type:** Field.
**Description:**
  Define for linear damping of the body.
**Signature:**
```tl
linearDamping: number
```
## angularDamping
**Type:** Field.
**Description:**
  Define for angular damping of the body.
**Signature:**
```tl
angularDamping: number
```
## linearAcceleration
**Type:** Field.
**Description:**
  Define for initial linear acceleration of the body.
**Signature:**
```tl
linearAcceleration: Vec2
```
## fixedRotation
**Type:** Field.
**Description:**
  Whether the body's rotation is fixed or not.
**Signature:**
```tl
fixedRotation: boolean
```
## bullet
**Type:** Field.
**Description:**
  Whether the body is a bullet or not.
Set to true to add extra bullet movement check for the body.
**Signature:**
```tl
bullet: boolean
```
## attachPolygon
**Type:** Function.
**Description:**
  Attaches a polygon fixture definition to the body.
**Signature:**
```tl
attachPolygon: function(self: BodyDef,
center: Vec2,
width: number,
height: number,
angle?: number --[[0.0]],
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| center | Vec2 | The center point of the polygon. |
| width | number | The width of the polygon. |
| height | number | The height of the polygon. |
| angle | number | [optional] The angle of the polygon (default is 0.0). |
| density | number | [optional] The density of the polygon (default is 0.0). |
| friction | number | [optional] The friction of the polygon (default is 0.4, should be 0 to 1.0). |
| restitution | number | [optional] The restitution of the polygon (default is 0.0, should be 0 to 1.0). |
## attachPolygon
**Type:** Function.
**Description:**
  Attaches a polygon fixture definition to the body.
**Signature:**
```tl
attachPolygon: function(self: BodyDef,
width: number,
height: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| width | number | The width of the polygon. |
| height | number | The height of the polygon. |
| density | number | [optional] The density of the polygon (default is 0.0). |
| friction | number | [optional] The friction of the polygon (default is 0.4, should be 0 to 1.0). |
| restitution | number | [optional] The restitution of the polygon (default is 0.0, should be 0 to 1.0). |
## attachPolygon
**Type:** Function.
**Description:**
  Attaches a polygon fixture definition to the body.
**Signature:**
```tl
attachPolygon: function(self: BodyDef,
vertices: {Vec2},
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| vertices | \{Vec2} | The vertices of the polygon. |
| density | number | [optional] The density of the polygon (default is 0.0). |
| friction | number | [optional] The friction of the polygon (default is 0.4, should be 0 to 1.0). |
| restitution | number | [optional] The restitution of the polygon (default is 0.0, should be 0 to 1.0). |
## attachMulti
**Type:** Function.
**Description:**
  Attaches a concave shape definition made of multiple convex shapes to the body.
**Signature:**
```tl
attachMulti: function(self: BodyDef,
vertices: {Vec2},
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| vertices | \{Vec2} | A table containing the vertices of each convex shape that makes up the concave shape.<br/>Each convex shape in the vertices table should ends with a Vec2(0.0, 0.0) as seperator. |
| density | number | [optional] The density of the concave shape (default is 0.0). |
| friction | number | [optional] The friction of the concave shape (default is 0.4, should be 0 to 1.0). |
| restitution | number | [optional] The restitution of the concave shape (default is 0.0, should be 0 to 1.0). |
## attachDisk
**Type:** Function.
**Description:**
  Attaches a disk fixture definition to the body.
**Signature:**
```tl
attachDisk: function(self: BodyDef,
center: Vec2,
radius: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| center | Vec2 | The center point of the disk. |
| radius | number | The radius of the disk. |
| density | number | [optional] The density of the disk (default is 0.0). |
| friction | number | [optional] The friction of the disk (default is 0.4, should be 0 to 1.0). |
| restitution | number | [optional] The restitution of the disk (default is 0.0, should be 0 to 1.0). |
## attachDisk
**Type:** Function.
**Description:**
  Attaches a disk fixture to the body.
**Signature:**
```tl
attachDisk: function(self: BodyDef,
radius: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| radius | number | The radius of the disk. |
| density | number | [optional] The density of the disk (default is 0.0). |
| friction | number | [optional] The friction of the disk (default is 0.4). |
| restitution | number | [optional] The restitution of the disk (default is 0.0). |
## attachChain
**Type:** Function.
**Description:**
  Attaches a chain fixture definition to the body. The Chain fixture is a free form sequence of line segments that has two-sided collision.
**Signature:**
```tl
attachChain: function(self: BodyDef,
vertices: {Vec2},
friction?: number --[[0.4]],
restitution?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| vertices | \{Vec2} | The vertices of the chain. |
| friction | number | [optional] The friction of the chain (default is 0.4). |
| restitution | number | [optional] The restitution of the chain (default is 0.0). |
## attachPolygonSensor
**Type:** Function.
**Description:**
  Attaches a polygon sensor fixture definition to the body.
**Signature:**
```tl
attachPolygonSensor: function(self: BodyDef,
tag: integer,
width: number,
height: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| tag | number | An integer tag for the sensor. |
| width | number | The width of the polygon. |
| height | number | The height of the polygon. |
## attachPolygonSensor
**Type:** Function.
**Description:**
  Attaches a polygon sensor fixture definition to the body.
**Signature:**
```tl
attachPolygonSensor: function(self: BodyDef,
tag: integer,
center: Vec2,
width: number,
height: number,
angle?: number --[[0.0]])
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| tag | number | An integer tag for the sensor. |
| center | Vec2 | The center point of the polygon. |
| width | number | The width of the polygon. |
| height | number | The height of the polygon. |
| angle | number | [optional] The angle of the polygon (default is 0.0). |
## attachPolygonSensor
**Type:** Function.
**Description:**
  Attaches a polygon sensor fixture definition to the body.
**Signature:**
```tl
attachPolygonSensor: function(self: BodyDef,
tag: integer,
vertices: {Vec2})
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| tag | number | An integer tag for the sensor. |
| vertices | \{Vec2} | A table containing the vertices of the polygon. |
## attachDiskSensor
**Type:** Function.
**Description:**
  Attaches a disk sensor fixture definition to the body.
**Signature:**
```tl
attachDiskSensor: function(self: BodyDef,
tag: integer,
center: Vec2,
radius: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| tag | number | An integer tag for the sensor. |
| center | Vec2 | The center of the disk. |
| radius | number | The radius of the disk. |
## attachDiskSensor
**Type:** Function.
**Description:**
  Attaches a disk sensor fixture to the body.
**Signature:**
```tl
attachDiskSensor: function(self: BodyDef,
tag: integer,
radius: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| tag | number | An integer tag for the sensor. |
| radius | number | The radius of the disk. |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。