BaseContainer
The base container is intended to be used by extending it on the creation of new Screens, Devices, Instruments, Elements and any thing else that needs to have access to base utility functions on the class instance.
When accessing assets from the shared asset loader, the asset manager prefixes global and local to the key used when the asset was set. "global" and "local" in this context refer to the whether an asset is a part of the object's resources and is not be confused with scope.
All assets set in the shared asset manager (SAM) are accessible globally. Auto-generated sprites are automatically given a prefix of the creating object's originRef and is best practice to use that object's resources only and not share resources for various Screen/Device/Instrument/ Elements.
JLS.core.BaseContainer
MyContainer extends BaseContainer
// Implementation example
import { BaseContainer } from 'path/to/core'
class MyContainer extends BaseContainer {
// code ommitted for brevity
}
Members
originRef
A string reference that can be set to uniquely identify this object.
originX
The X position of this object on a canvas.
originY
The Y position of this object on a canvas.
originW
The width of the object when displayed on a canvas.
originH
The height of the ojbect when displayed on a canvas.
objState
A string that can be set to determine what "state" the object is in at runtime.
sprites
A collection of local assets that only the object can see and use.
Methods
setOriginRef(ref)
Sets the origin reference of the object with a unique id. Returns the current originRef of the object as a convenience method to ensure correct unique id has been set.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| ref | string | this.originRef | unique reference for this object. |
setOrigin(x, y)
Sets the "origin" or position of the object. Returns the current position after it has been set to the object as a convenience method to ensure correct origin has been set. This method should be used after add items to a container or unexpected behavior can occur.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| x | number | this.originX | position relative to the parent container. |
| y | number | this.originY | position relative to the paraent container. |
setDimensions(w, h)
Sets the size of the object. Returns the current size of the object as a convenience method to ensure correct origin has been set.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| w | number | this.originW | width of the object. |
| h | number | this.originH | height of the object. |
setObjectState(state)
Sets the state of the object.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| state | string | --- | an arbitrary value that can be set as "state". |
setAlpha(value, object)
Sets the alpha (opacity) of the container. If wished to hide and not have any interactivity with the object. setVisibility method should be used instead.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | float | --- | the opacity from 0-1. 1 having no transparency. |
| object | PIXI object (i.e.: Container, Graphic, etc.) | --- | the PIXI display object to set alpha property. |
setVisibility(value, object)
Sets the visibility of a pixi display object. Method can be used to toggle visibility of a child element or the parent container if this is passed as the object. If visibility is set to 0, the object will not be able to be interacted with. If interactivity is desired, use setAlpha method instead.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | integer | --- | the value (0 or 1) to set. 1 is visible, 0 is not. |
| object | PIXI object (i.e.: Container, Graphic, etc.) | --- | the PIXI display object to set visible property. |
setBackground(fillColor, options)
Add a colored region that spans the entire area of the container it is called on. forceToBack option shifts it's position as the first child in the container which places all the children above it making it a "background." By setting forceToBack false, it is added as normal at the next index available.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| fillColor | string | --- | the hexcode to set (i.e.: "000000"). |
| options | object | --- | see options and their defaults below. |
options
| Name | Type | Default | Description |
|---|---|---|---|
| lineColor | string | null | the color hexcode to set (i.e.: "000000") as the shape's border. |
| lineThickness | number | null | the stroke of the shape's border. |
| bevels | number | null | the border radius of the shape. |
| opacity | float | 1.0 | the opacity of the shape. |
| forceToBack | boolean | true | makes the shape the first "layout" in the stack so all other objects appear infront of it. |
makeInteractive(buttonMode, object)
Makes the object able to trigger events when interacted with. Able to specify the PIXI display object; If none provided, the container that called the method is made interactive.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| buttonMode | boolean | false | enable cursor change on hover (desktop only). |
| object | PIXI Object (i.e.: Container, Graphic) | --- | the PIXI object to make interactive. |