# m4m.framework.rectBody2d

[@meta4d/engine](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs.md) / [Exports](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/modules.md) / [m4m](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/modules/m4m.md) / [framework](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/modules/m4m.framework.md) / rectBody2d

## Class: rectBody2d

[m4m](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/modules/m4m.md).[framework](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/modules/m4m.framework.md).rectBody2d

**`language`** zh\_CN

**`classdesc`** 矩形 2d刚体

**`version`** m4m 1.0

### Hierarchy

* [`physics2DBody`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md)

  ↳ **`rectBody2d`**

### Table of contents

#### Properties

* [\_physicsEngine](#_physicsengine)
* [body](#body)
* [enabled](#enabled)
* [onInit](#oninit)
* [options](#options)
* [transform](#transform)
* [ClassName](#classname)

#### Methods

* [addForce](#addforce)
* [afterStep](#afterstep)
* [beforeStep](#beforestep)
* [isSensor](#issensor)
* [isSleeping](#issleeping)
* [isStatic](#isstatic)
* [onPlay](#onplay)
* [remove](#remove)
* [setAngle](#setangle)
* [setAngularVelocity](#setangularvelocity)
* [setCentre](#setcentre)
* [setDensity](#setdensity)
* [setFriction](#setfriction)
* [setFrictionAir](#setfrictionair)
* [setFrictionStatic](#setfrictionstatic)
* [setInertia](#setinertia)
* [setInitData](#setinitdata)
* [setMass](#setmass)
* [setParts](#setparts)
* [setPosition](#setposition)
* [setRestitution](#setrestitution)
* [setScale](#setscale)
* [setSleeping](#setsleeping)
* [setStatic](#setstatic)
* [setVelocity](#setvelocity)
* [setVertices](#setvertices)
* [start](#start)
* [update](#update)

#### Constructors

* [constructor](#constructor)

#### Accessors

* [physicsEngine](#physicsengine)
* [positionOffset](#positionoffset)

### Properties

#### \_physicsEngine

• `Protected` **\_physicsEngine**: [`physicEngine2D`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physicengine2d.md)

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[\_physicsEngine](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#_physicsengine)

**Defined in**

[framework/2d/physicEngine/basebody.ts:116](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L116)

***

#### body

• **body**: [`Ibody`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.ibody.md)

物理世界body

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[body](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#body)

**Defined in**

[framework/2d/physicEngine/basebody.ts:132](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L132)

***

#### enabled

• **enabled**: `boolean` = `true`

**`language`** zh\_CN

**`classdesc`** 组件启用

**`version`** m4m 1.0

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[enabled](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#enabled)

**Defined in**

[framework/2d/component/behaviour2d.ts:16](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/component/behaviour2d.ts#L16)

***

#### onInit

• **onInit**: (`phy2dBody`: [`I2DPhysicsBody`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.i2dphysicsbody.md)) => `any`

**Type declaration**

▸ (`phy2dBody`): `any`

物理对象初始化完成回调

**Parameters**

| Name        | Type                                                                                                   |
| ----------- | ------------------------------------------------------------------------------------------------------ |
| `phy2dBody` | [`I2DPhysicsBody`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.i2dphysicsbody.md) |

**Returns**

`any`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[onInit](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#oninit)

**Defined in**

[framework/2d/physicEngine/basebody.ts:134](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L134)

***

#### options

• **options**: [`I2dPhyBodyData`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.i2dphybodydata.md) = `{}`

body 选项数据

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[options](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#options)

**Defined in**

[framework/2d/physicEngine/basebody.ts:251](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L251)

***

#### transform

• **transform**: [`transform2D`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.transform2d.md)

绑定的UI

**Overrides**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[transform](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#transform)

**Defined in**

[framework/2d/physicEngine/rectBody2d.ts:17](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/rectBody2d.ts#L17)

***

#### ClassName

▪ `Static` `Readonly` **ClassName**: `string` = `"rectBody2d"`

**Defined in**

[framework/2d/physicEngine/rectBody2d.ts:16](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/rectBody2d.ts#L16)

### Methods

#### addForce

▸ **addForce**(`Force`): `void`

施加作用力

**Parameters**

| Name    | Type                                                                            |
| ------- | ------------------------------------------------------------------------------- |
| `Force` | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md) |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[addForce](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#addforce)

**Defined in**

[framework/2d/physicEngine/basebody.ts:187](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L187)

***

#### afterStep

▸ **afterStep**(): `void`

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[afterStep](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#afterstep)

**Defined in**

[framework/2d/physicEngine/basebody.ts:387](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L387)

***

#### beforeStep

▸ **beforeStep**(): `void`

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[beforeStep](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#beforestep)

**Defined in**

[framework/2d/physicEngine/basebody.ts:371](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L371)

***

#### isSensor

▸ **isSensor**(): `boolean`

是否是传感器 A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically.

**Returns**

`boolean`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[isSensor](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#issensor)

**Defined in**

[framework/2d/physicEngine/basebody.ts:179](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L179)

***

#### isSleeping

▸ **isSleeping**(): `boolean`

是否已休眠 A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken. If you need to set a body as sleeping, you should use `Sleeping.set` as this requires more than just setting this flag.

**Returns**

`boolean`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[isSleeping](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#issleeping)

**Defined in**

[framework/2d/physicEngine/basebody.ts:164](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L164)

***

#### isStatic

▸ **isStatic**(): `boolean`

是否是静态 A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed. If you need to set a body as static after its creation, you should use `Body.setStatic` as this requires more than just setting this flag.

**Returns**

`boolean`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[isStatic](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#isstatic)

**Defined in**

[framework/2d/physicEngine/basebody.ts:172](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L172)

***

#### onPlay

▸ **onPlay**(): `void`

初始化使用 在start 之后

**Returns**

`void`

**Overrides**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[onPlay](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#onplay)

**Defined in**

[framework/2d/physicEngine/rectBody2d.ts:25](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/rectBody2d.ts#L25)

***

#### remove

▸ **remove**(): `void`

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[remove](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#remove)

**Defined in**

[framework/2d/physicEngine/basebody.ts:452](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L452)

***

#### setAngle

▸ **setAngle**(`angle`): `void`

设置旋转角度

**Parameters**

| Name    | Type     |
| ------- | -------- |
| `angle` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setAngle](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setangle)

**Defined in**

[framework/2d/physicEngine/basebody.ts:285](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L285)

***

#### setAngularVelocity

▸ **setAngularVelocity**(`velocity`): `void`

设置角速度

**Parameters**

| Name       | Type     |
| ---------- | -------- |
| `velocity` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setAngularVelocity](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setangularvelocity)

**Defined in**

[framework/2d/physicEngine/basebody.ts:202](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L202)

***

#### setCentre

▸ **setCentre**(`centre`, `relative?`): `void`

设置中心点 Set the centre of mass of the body. The `centre` is a vector in world-space unless `relative` is set, in which case it is a translation. The centre of mass is the point the body rotates about and can be used to simulate non-uniform density. This is equal to moving `body.position` but not the `body.vertices`. Invalid if the `centre` falls outside the body's convex hull.

**Parameters**

| Name       | Type                                                                            | Default value |
| ---------- | ------------------------------------------------------------------------------- | ------------- |
| `centre`   | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md) | `undefined`   |
| `relative` | `boolean`                                                                       | `false`       |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setCentre](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setcentre)

**Defined in**

[framework/2d/physicEngine/basebody.ts:359](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L359)

***

#### setDensity

▸ **setDensity**(`Desity`): `void`

设置密度

**Parameters**

| Name     | Type     |
| -------- | -------- |
| `Desity` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setDensity](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setdensity)

**Defined in**

[framework/2d/physicEngine/basebody.ts:210](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L210)

***

#### setFriction

▸ **setFriction**(`friction`): `void`

设置摩擦力

**Parameters**

| Name       | Type     |
| ---------- | -------- |
| `friction` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setFriction](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setfriction)

**Defined in**

[framework/2d/physicEngine/basebody.ts:225](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L225)

***

#### setFrictionAir

▸ **setFrictionAir**(`frictionAir`): `void`

设置空气摩擦力

**Parameters**

| Name          | Type     |
| ------------- | -------- |
| `frictionAir` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setFrictionAir](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setfrictionair)

**Defined in**

[framework/2d/physicEngine/basebody.ts:218](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L218)

***

#### setFrictionStatic

▸ **setFrictionStatic**(`frictionStatic`): `void`

设置静态摩擦力

**Parameters**

| Name             | Type     |
| ---------------- | -------- |
| `frictionStatic` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setFrictionStatic](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setfrictionstatic)

**Defined in**

[framework/2d/physicEngine/basebody.ts:232](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L232)

***

#### setInertia

▸ **setInertia**(`Inertia`): `void`

设置惯性值 Sets the moment of inertia (i.e. second moment of area) of the body. Inverse inertia is automatically updated to reflect the change. Mass is not changed.

**Parameters**

| Name      | Type     |
| --------- | -------- |
| `Inertia` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setInertia](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setinertia)

**Defined in**

[framework/2d/physicEngine/basebody.ts:326](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L326)

***

#### setInitData

▸ **setInitData**(`options`): `void`

设置选项数据

**Parameters**

| Name      | Type                                                                                                   | Description |
| --------- | ------------------------------------------------------------------------------------------------------ | ----------- |
| `options` | [`I2dPhyBodyData`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.i2dphybodydata.md) | 选项数据        |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setInitData](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setinitdata)

**Defined in**

[framework/2d/physicEngine/basebody.ts:256](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L256)

***

#### setMass

▸ **setMass**(`mass`): `void`

设置质量

**Parameters**

| Name   | Type     |
| ------ | -------- |
| `mass` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setMass](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setmass)

**Defined in**

[framework/2d/physicEngine/basebody.ts:247](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L247)

***

#### setParts

▸ **setParts**(`parts`, `autoHull?`): `void`

设置成员 Sets the parts of the `body` and updates mass, inertia and centroid. Each part will have its parent set to `body`. By default the convex hull will be automatically computed and set on `body`, unless `autoHull` is set to `false.` Note that this method will ensure that the first part in `body.parts` will always be the `body`.

**Parameters**

| Name       | Type                                                                                    | Default value |
| ---------- | --------------------------------------------------------------------------------------- | ------------- |
| `parts`    | [`Ibody`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.framework.ibody.md)\[] | `undefined`   |
| `autoHull` | `boolean`                                                                               | `true`        |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setParts](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setparts)

**Defined in**

[framework/2d/physicEngine/basebody.ts:348](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L348)

***

#### setPosition

▸ **setPosition**(`pos`): `void`

设置位置

**Parameters**

| Name  | Type                                                                            | Description |
| ----- | ------------------------------------------------------------------------------- | ----------- |
| `pos` | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md) | 位置vec2      |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setPosition](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setposition)

**Defined in**

[framework/2d/physicEngine/basebody.ts:264](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L264)

***

#### setRestitution

▸ **setRestitution**(`restitution`): `void`

设置还原张力

**Parameters**

| Name          | Type     |
| ------------- | -------- |
| `restitution` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setRestitution](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setrestitution)

**Defined in**

[framework/2d/physicEngine/basebody.ts:239](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L239)

***

#### setScale

▸ **setScale**(`scale`): `void`

**Parameters**

| Name    | Type                                                                            |
| ------- | ------------------------------------------------------------------------------- |
| `scale` | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md) |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setScale](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setscale)

**Defined in**

[framework/2d/physicEngine/basebody.ts:301](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L301)

***

#### setSleeping

▸ **setSleeping**(`isSleeping`): `void`

设置休眠状态

**Parameters**

| Name         | Type      |
| ------------ | --------- |
| `isSleeping` | `boolean` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setSleeping](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setsleeping)

**Defined in**

[framework/2d/physicEngine/basebody.ts:318](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L318)

***

#### setStatic

▸ **setStatic**(`isStatic`): `void`

设置静态状态 Sets the body as static, including isStatic flag and setting mass and inertia to Infinity.

**Parameters**

| Name       | Type      |
| ---------- | --------- |
| `isStatic` | `boolean` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setStatic](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setstatic)

**Defined in**

[framework/2d/physicEngine/basebody.ts:312](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L312)

***

#### setVelocity

▸ **setVelocity**(`velocity`): `void`

设置速度

**Parameters**

| Name       | Type                                                                            |
| ---------- | ------------------------------------------------------------------------------- |
| `velocity` | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md) |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setVelocity](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setvelocity)

**Defined in**

[framework/2d/physicEngine/basebody.ts:194](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L194)

***

#### setVertices

▸ **setVertices**(`vertices`): `void`

设置顶点 Sets the body's vertices and updates body properties accordingly, including inertia, area and mass (with respect to `body.density`). Vertices will be automatically transformed to be orientated around their centre of mass as the origin. They are then automatically translated to world space based on `body.position`.

The `vertices` argument should be passed as an array of `Matter.Vector` points (or a `Matter.Vertices` array). Vertices must form a convex hull, concave hulls are not supported.

**Parameters**

| Name       | Type                                                                               |
| ---------- | ---------------------------------------------------------------------------------- |
| `vertices` | [`Ivec2`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/interfaces/m4m.math.ivec2.md)\[] |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[setVertices](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#setvertices)

**Defined in**

[framework/2d/physicEngine/basebody.ts:338](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L338)

***

#### start

▸ **start**(): `void`

初始化使用

**Returns**

`void`

**Overrides**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[start](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#start)

**Defined in**

[framework/2d/physicEngine/rectBody2d.ts:19](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/rectBody2d.ts#L19)

***

#### update

▸ **update**(`delta`): `void`

每帧调用一次

**Parameters**

| Name    | Type     |
| ------- | -------- |
| `delta` | `number` |

**Returns**

`void`

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[update](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#update)

**Defined in**

[framework/2d/physicEngine/basebody.ts:367](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L367)

### Constructors

#### constructor

• **new rectBody2d**()

**Inherited from**

[physics2DBody](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md).[constructor](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physics2dbody.md#constructor)

**Defined in**

[framework/2d/physicEngine/basebody.ts:118](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L118)

### Accessors

#### physicsEngine

• `get` **physicsEngine**(): [`physicEngine2D`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physicengine2d.md)

2d物理引擎实例对象

**Returns**

[`physicEngine2D`](/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.physicengine2d.md)

**Inherited from**

physics2DBody.physicsEngine

**Defined in**

[framework/2d/physicEngine/basebody.ts:109](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L109)

***

#### positionOffset

• `get` **positionOffset**(): `vector2`

物理对象 碰撞体位置偏移量

**Returns**

`vector2`

**Inherited from**

physics2DBody.positionOffset

**Defined in**

[framework/2d/physicEngine/basebody.ts:138](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L138)

• `set` **positionOffset**(`pos`): `void`

物理对象 碰撞体位置偏移量

**Parameters**

| Name  | Type      |
| ----- | --------- |
| `pos` | `vector2` |

**Returns**

`void`

**Inherited from**

physics2DBody.positionOffset

**Defined in**

[framework/2d/physicEngine/basebody.ts:139](https://github.com/meta4d-me/meta4d-engine/blob/cf6bfe6/src/framework/2d/physicEngine/basebody.ts#L139)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://engine-docs.meta4d.me/jkUDC53bibxMH5jKxZe0/api-docs/api-docs/classes/m4m.framework.rectbody2d.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
