DisplayEngine
Creates the renderer and root container. Optionally, a root container can be specified.
JLS.engines.DsiplayEngine
class DisplayEngine(options)
// Implementation example
import { DisplayEngine, GameEngine } from 'path/to/engines'
import { Screen } from 'path/to/core'
const displayEngine = new DisplayEngine({
width : 1920,
height : 1080,
fallbackBgColor : 'FFFFFF',
scaleBoxBgColor : 'FFFFFF',
canvasScaling : 'autoScale',
allowScaleDown : true,
})
const TestScreen = new Screen()
// Set a shared display (optional)
DisplayEngine.setShared(displayEngine)
// Below Methods called later, usually when all assets finished loading
// If no assets, load can be called manually
// Set a screen to be the main container for the "scene."
// This will usually be a JLS.Screen, but can be any PIXI.Container object
displayEngine.set(TestScreen)
// Begin rendering the display. This is the most important step!!! If this isn't done,
// you won't see anything because it is not continously rendering anything.
GameEngine.register(displayEngine.render)
options
The word "options" is used somewhat loosely here as most of the fields are required. Actual optional parameters will have an optional flag.
See PIXI.Renderer for list of options. Only custom and commonly used options are shown here.
| Name | Type | Default | Description |
|---|---|---|---|
| autoDensity | boolean | true | optional Resizes renderer view in CSS pixels to allow for resolutions other than 1. |
| antialias | boolean | true | optional Sets antialias. If not available natively then FXAA antialiasing is used. |
| displayArea | string | fill | optional Where to display the canvas. Fill with remove all HTML body elements and only one canvas element will be shown. Another option is to specify the id of the element to use. |
| scaleBoxBgColor | string | 090E14 | optional The color of the area not completely filled by the canvas when scaling. |
| canvasScaling | string | fixed | optional options: fixed, auto, autoScale Fixed applies no scaling, auto scales, but doesn't resize, autoScale scales and resizes in center of screen. |
| autoResize | boolean | true | optional Whether to resize the canvas if the browser width/height changes after it is setup. |
| allowScaleDown | boolean | true | optional Whether to allow the canvas to be smaller than it's originW and originH. |
| canvasPadding | number | 10 | optional Padding around the canvas. |
| disableContextMenu | boolean | true | optional Whether to disable the default right click browser mouse options context menu. |
Members
get static
Reference to the renderer's canvas element.
view
Get the shared instance of the class that is used.
Methods
setRootDisplay(displayObj)
Sets the root display container that's rendered. If none is passed as a parameter. An empty PIXI.Container is created and used.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| displayObj | PIXI.DisplayObject | PIXI.Container | The container to use as a stage for rendering everything else. |
set(displayObj)
Alias of setRootDisplay.
render(delta)
Renders the current stage.
setShared(obj) static
Sets the shared instance to use between classes.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| obj | PIXI.DisplayObject | PIXI.Container | The container to use as a stage for rendering everything else. |
screen()
Reference to the renderer's screen rectangle. Its safe to use as filterArea or hitArea for the whole screen.
resize()
Resize the to the desired scaling method. Sets a scale factor, which is useful for adjusting child elements or other graphics to match the appropriate scale. Scaling options: (1) auto, centers canvas both horizontally/vertically; (2) autoScale, centers canvas both horizontally/vertically and scales to fit.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| autoResize | boolean | true | Allows the display to adjust to the screen's size. |
init()
Initializes the display engine (called automatically) on construction.