Constructor
new JRender(optionsopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
physics.JRender.Options |
<optional> |
null | Configuration object. |
- Source:
Example
// Create jrender instance:
this.jrender = new physics.JRender({ptsPerMeterFactor:0.5});
Members
links :Object
Lookup of `JSyncLink` instances.
- Each link will be referenced by its label.
- Each link will be referenced by its label.
Type:
- Object
- Source:
(readonly, non-null) mouseElement :DOMElement
Returns the appropriate HMTL element to supply to the constructor of the `matter.js` Mouse.
Type:
- DOMElement
- Source:
Example
this.mouse = Mouse.create(this.jrender.mouseElement);
mtp :number
Meters to points: Multiply by this to translate `matter.js` units (in meters) to (art) pts.
- This property is used by the conversion methods.
- This property is used by the conversion methods.
Type:
- number
- Source:
ptm :number
Points to meters: Multiply by this to translate (art) pt to `matter.js` units (in meters).
- This property is used by the conversion methods.
- This property is used by the conversion methods.
Type:
- number
- Source:
Methods
addSyncLink(label, link) → {physics.JSyncLink}
Adds a sync link to the JRender's `links`.
- This is automatically performed by the `createSyncLink()` method.
- This is automatically performed by the `createSyncLink()` method.
Parameters:
Name | Type | Description |
---|---|---|
label |
string | Label for the link. |
link |
physics.JSyncLink | The link to added. |
- Source:
Returns:
link - The newly added link object.
- Type
- physics.JSyncLink
adjustMouseToStage(mouse)
Adjusts a `matter.js` mouse instance to match the current stage dimensions.
Parameters:
Name | Type | Description |
---|---|---|
mouse |
Matter.Mouse | Mouse instance. |
- Source:
applySync(label, labelopt)
Syncs the link to the physics engine state.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
label |
string | Label associated with link. | ||
label |
boolean |
<optional> |
false | If true will update the link regardless of its `syncEnabled` state. |
- Source:
artPtsToPhysMtrs(artPts) → {number}
Converts PSD art pts measurement to the physics engine coordinate space meters.
Parameters:
Name | Type | Description |
---|---|---|
artPts |
number | PSD art pts. |
- Source:
Returns:
physMtrs - Physics engine meters.
- Type
- number
createSyncLink(label, from, to, syncPropsopt, valueModifiersopt, syncCallbackopt) → {physics.JSyncLink}
Creates a new `JSyncLink` and adds to the JRender's `links`.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
label |
string | Label for the link. | ||
from |
Matter.Body | Physics body (the leader). | ||
to |
PIXI.DisplayObject | Display object (the follower). | ||
syncProps |
JRender.SyncProps |
<optional> |
null | Which properties to sync. |
valueModifiers |
JRender.SyncValueModifiers |
<optional> |
null | Sync value modfiers. |
syncCallback |
JRender.SyncCallback |
<optional> |
null | Optional function to call after each sync. |
- Source:
Returns:
link - The newly created link object.
- Type
- physics.JSyncLink
dispoToBodyDef(dispo) → {JRender.BodyDef}
Converts a PIXI display object to a `matter.js` body definition to be used to create a physics body.
Parameters:
Name | Type | Description |
---|---|---|
dispo |
PIXI.DisplayObject | Display Object. Center registration is assumed. |
- Source:
Returns:
bodyDef - Body definition.
- Type
- JRender.BodyDef
drawRender(rectangle)
Called by `JRunner` once every tick, after physics engine has updated.
- Each link will be synced to the new physics engine state.
- Each link will be synced to the new physics engine state.
Parameters:
Name | Type | Description |
---|---|---|
rectangle |
PIXI.Rectangle |
- Source:
physMtrsToArtPts(physMtrs) → {number}
Converts physics engine coordinate space meters measurement to PSD art pts.
Parameters:
Name | Type | Description |
---|---|---|
physMtrs |
number | Physics engine meters. |
- Source:
Returns:
artPts - PSD art pts.
- Type
- number
physMtrsToScreenPts(physMtrs) → {number}
Convert physics engine coordinate space meters measurement to screen pts (css).
Parameters:
Name | Type | Description |
---|---|---|
physMtrs |
number | Physics engine meters. |
- Source:
Returns:
screenPts - Screen pt measurement (css).
- Type
- number
rectToBodyDef(rectangle) → {JRender.BodyDef}
Convert PIXI.Rectangle to a `matter.js` body definition.
Parameters:
Name | Type | Description |
---|---|---|
rectangle |
PIXI.Rectangle |
- Source:
Returns:
bodyDef - Body definition.
- Type
- JRender.BodyDef
removeSyncLink(label, disposeopt) → {physics.JSyncLink}
Removes a sync link from JRender's `links`.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
label |
string | Label for the link. | ||
dispose |
boolean |
<optional> |
true | Whether to destroy the link. |
- Source:
Returns:
link - The removed link.
- Type
- physics.JSyncLink
screenPtsToPhysMtrs(screenPts) → {number}
Convert screen pts (css) measurement to physics engine coordinate space meters.
- Default scaler projection assumed.
- Default scaler projection assumed.
Parameters:
Name | Type | Description |
---|---|---|
screenPts |
number | Screen pt measurement (css). |
- Source:
Returns:
physMtrs - Physics engine meters.
- Type
- number
screenXToPhysMtrs(screenX) → {number}
Convert screen x pt position to physics engine coordinate space meters.
- This will take into account the offset of the projected artboard.
- Default scaler projection assumed.
- This will take into account the offset of the projected artboard.
- Default scaler projection assumed.
Parameters:
Name | Type | Description |
---|---|---|
screenX |
number | Screen x position in pts (css). |
- Source:
Returns:
physMtrsX - Physics engine meters.
- Type
- number
screenYToPhysMtrs(screenY) → {number}
Convert screen y pt position to physics engine coordinate space meters.
- This will take into account the offset of the projected artboard.
- Default scaler projection assumed.
- This will take into account the offset of the projected artboard.
- Default scaler projection assumed.
Parameters:
Name | Type | Description |
---|---|---|
screenY |
number | Screen y position in pts (css). |
- Source:
Returns:
physMtrsY - Physics engine meters.
- Type
- number
txInfoToBodyDef(txInfo) → {JRender.BodyDef}
Convert `storymode` `txInfo` (or string `txPath`) to a `matter.js` body definition.
- Will throw an error if texture path not found.
- Will throw an error if texture path not found.
Parameters:
Name | Type | Description |
---|---|---|
txInfo |
string | Object | Texture info path (eg. `myart.psd/mysprite`) or object. |
- Source:
Returns:
bodyDef - Body definition.
- Type
- JRender.BodyDef
Type Definitions
BodyDef
A `matter.js` object defining properties to be used to create a physics body.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
width |
number | Width. |
height |
number | Height. |
cx |
number | Center x. |
cy |
number | Center y. |
- Source:
SyncCallback(link)
An optional callback fired at the end of each link sync.
Parameters:
Name | Type | Description |
---|---|---|
link |
physics.JSyncLink | The link being synced. |
- Source:
SyncProps
A config object indicating which properties to sync.
-If all syncProps are false (or not properties defined), the remaining are assumed true
-If any sync props are true, the remaining are assumed false.
-If all syncProps are false (or not properties defined), the remaining are assumed true
-If any sync props are true, the remaining are assumed false.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
x |
boolean | Sync x position. |
y |
boolean | Sync y position. |
rotation |
boolean | Sync rotation. |
scale |
boolean | Sync scale. |
- Source:
SyncValueModifiers
Adjust the values being synced to the display object.
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number |
<optional> |
0 | X value to be added to the sync value (in physics meters). |
y |
number |
<optional> |
0 | Y value to be added to the sync value (in physics meters). |
rotatio |
number |
<optional> |
0 | Rotation to be added to the sync value (in radians). |
scale |
number |
<optional> |
1.0 | Scale to be multiplied by the sync value. |
- Source: