Class: DisplayObject

PIXI.DisplayObject

Methods

(static) fromTx(texturePath, addChildrenopt, frame|textContentopt) → {PIXI.DisplayObject}

Loads supplied texture to target class automatically scaled and positioned based on the projection properties of the `scaler` class.
- Optionally supply a clipping frame - which is handly for cutting up a sprite at runtime.
- Supports `PIXI.Text`, `PIXI.Graphics`, `PIXI.AnimatedSprite`, `PIXI.Sprite`, `PIXI.Container`.
Parameters:
Name Type Attributes Default Description
texturePath string A reference to the containing PSD document and layer name, separated by a forward slash. Eg. `mydoc.psd/mysprite`.
addChildren boolean <optional>
true If `true` then the display object's nested children will be added as well.
frame|textContent PIXI.Rectangle | string <optional>
null For a sprite will clip the texture to the supplied frame rect. Not compatible with spritesheet assets. Will be taken into account with `dispo.applyProj()`. For text this paramer will overwrite the containing text of the field.
Source:
Returns:
displayObject - Display object instance.
Type
PIXI.DisplayObject
Example
let mySpr = Sprite.fromTx(this.psdID + '/' + 'mysprite');
this.addChild(mySpr); // Sprite will be at projected scale and position.

addArt(…textureNameGlobopt) → {Array.<PIXI.DisplayObject>}

Will add all matching textures to the calling instance according to nesting, scale and position settings in the PSD export data and `scaler` class.
- This method is usually called by a `scene` and will load textures found in the PSD associated with the scene via the `psdID` property.
- Nested display objects (display objects within display objects) are automatically added as well.
- If caller is a scene then all top level items are added otherwise will add chidren only.
- `textureNameGlob` array is also passed to any children.
- All display objects added will also be appended to a property called `art` of the calling instance, in a lookup object by texture name.
Parameters:
Name Type Attributes Default Description
textureNameGlob string <optional>
<repeatable>
null Optional texture names or wildcard pattern to include and/or exclude. Eg. `*_tx_suffix`, `!tf_match*`, `tx_prefix_*`
Source:
Returns:
added - An array of display objects added to the calling instance.
Type
Array.<PIXI.DisplayObject>
Example
// Adding art on scene load
didLoad(ev){
 super.didLoad(ev);
 const added = this.addArt('!healthbar', 'player_*', '!mountains*');
 const head = this.art.player_head; // Access added display object
 // ...
}

adjustForParentScale(updatePositionopt)

Will adjust child display object to retain the same scale despite the scale applied to its parent.
- Will throw an error if display object has not got a parent.
Parameters:
Name Type Attributes Default Description
updatePosition boolean <optional>
true If true will updated the child's position as well.
Source:

applyProj(syncPropsopt)

Applys the size and position based on the current stage dimensions and scaler projection.
- Called on each instance that `storymode` creates.
- Suitable to be called after a stage resize event.
Parameters:
Name Type Attributes Default Description
syncProps boolean | Array.<string> <optional>
false If not `false` will call `syncTxInfoToStage(...)` to update the `txInfo` first. Optional array of props: `width`,`height`,`x`,`y`,'pos','scale'. Eg. ['x','y'].
Source:

applyShake(traumaPerc, maxFactoropt, optionsopt, extraTargetsopt)

Will apply a cumulative screen shake and rotation.
- Primarily developed to be applied to the current scene.
- See: https://youtu.be/tu-Qe66AvtY?t=660
Parameters:
Name Type Attributes Default Description
traumaPerc number How much trauma/impact to apply in the range of 0.0 to 1.0.
maxFactor number <optional>
1.0 The shake limits will be multipled by this factor.
options number <optional>
null Options
Properties
Name Type Attributes Default Description
rotateOnly boolean <optional>
false If true then position will not be animated.
extraTargets Array | DisplayObject <optional>
false Any additional display objects that will be affected by the animation.
Source:

bringToFront()

Brings display object to the top of the display stack.
- Will throw an error if display object doesn't have a parent.
Source:

debugStack()

Outputs to console a representation of children of the given display object.
Source:

destroyFiltersAndMasks(recursive)

Removes filters and masks to display object and all children recursively.
- Called by scene on exit.
Parameters:
Name Type Description
recursive boolean Whether to call on children and their children.
Source:

getArt(…textureNameGlobopt)

Will return an array of texture names that match the supplied globs.
- Same as a dry run of `displayObject.addArt()`.
Parameters:
Name Type Attributes Default Description
textureNameGlob string <optional>
<repeatable>
null Optional texture names or wildcard pattern Eg. `*_tx_suffix`, `!tf_match*`, `tx_prefix_*`
Source:

hug(hugAlignment, hugDimensionsopt)

Postition a `PIXI.DisplayObject` relative to edge or center of stage or supplied dimension object, with the same offset as defined in the art PSD.
- This method takes the reg point into consideration when positioning.
Parameters:
Name Type Attributes Default Description
hugAlignment string A 1-2 chracter string configuring hug alignment. `T` means top aligned, `B` means bottom aligned, `L` means left aligned, `R` means right aligned. `C` means centered on x axis,`M` means centered on y axis and any unset axes will return `null`.
hugDimensions Object <optional>
null The dimensions to hug to. Will default to the stage dimensions.
Properties
Name Type Description
width number
height number
Source:
Example
myDispo.hug('BR'); // Positions display object bottom right of screen.

isCached() → {boolean}

Returns true if display object has applied cache as bitmap.
- The cache will be applied at the next render after cacheAsBitmap is enabled.
Source:
Returns:
isCached
Type
boolean

killBtn()

Resets and cleans up display object that was converted to button with `makeBtn()`.
Source:

killShake()

Stops and disposes of any screenshake in progress.
Source:

makeBtn(clickCallbackopt, stateChangeCallbackopt)

Converts the display object into a simple button.
Parameters:
Name Type Attributes Default Description
clickCallback number <optional>
null The function to call on click. If not set will fire `parent.onBtn()` or `parent.parent.onBtn()` if preset.
stateChangeCallback number <optional>
null Will trigger callback on state change.
Source:

removeFromParent()

Removes display object from parent.
Source:

sendToBack()

Sends display object to the back of the display stack.
- Will throw an error if display object doesn't have a parent.
Source:

setPivotWithoutMoving(pivotX, pivotY)

Applies the supplied pivot to the display object without moving the position, even if rotated.
Parameters:
Name Type Description
pivotX number
pivotY number
Source:

syncRelative(targetDispo, syncXopt, syncXopt)

Syncs the position relative to another, as defined in the PSD.
Parameters:
Name Type Attributes Default Description
targetDispo PIXI.DisplayObject The display object to sync relative to.
syncX boolean <optional>
true Whether to sync x position.
syncX boolean <optional>
true Whether to sync y position.
Source:
Example
this.art.targetSprite.position.set(scaler.stageW*0.5, scaler.stageH*0.5);
this.art.followerSprite.syncRelative(this.art.targetSprite)

syncTxInfoToStage(syncPropsopt, usePreviousopt)

Attempts to update the `txInfo` property of a `PIXI.DisplayObject` to match its current stage position and scale.
- The `usePrevious` is needed in a scenario when the stage has already resized and the scaler already updated and we need to go back to see the previous scaler state to work out the Display Object's relative stage position and scale.
Parameters:
Name Type Attributes Default Description
syncProps boolean | Array.<string> <optional>
true Optional array of props: `width`,`height`,`x`,`y`,'pos','scale'. Eg. ['x','y'].
usePrevious boolean <optional>
false Assumes the dispos's current position is relative to scaler.prev (the previous stage dimension info).
Source:

translateToCoordSpace()

Display object will remain in place from one parent coord space to another
- See https://pixijs.download/dev/docs/PIXI.AnimatedSprite.html#toGlobal
Source: