stage
A Stage acts as a convenience tool to hoist a canvas and begin drawing however it's not fundamental.
The Stage helps manage loading and looping of draw functions
Extend with your own custom functionality and run the go() method:
class MainStage extends Stage {
// canvas = document.getElementById('playspace');
canvas = 'playspace'
}
stage = MainStage.go({
loop: true
})
This will execute the canvas name. It provides some free tools:
mount()anddraw(ctx)functions- load capture events
- size locking and auto resizing
- optional request frame loop
- builtin measurement tools;
centeranddimensions
Meta Data
| dependencies | () |
| unused_keys | ('title',) |
| unknown_keys | ('files',) |
| files | ['', 'functions/resolve.js'] |
| filepath_exists | True |
| path | stage |
| filepath | stage.js |
| clean_files | ('functions/resolve.js',) |
-
ClassDeclarationclass
StageBase
extends Noneclass comments:an addon instance has anounced itself. Perform the addComponentClassDeclarationclassStageRender
extends StageBaseclass comments:Accept a `canvas` node and an optional `draw` function, prepare the stage draw routine. If the `canvas` is given, immediately call `this.prepare(canvas)` to initiate the layer. new StageRender(canvas, ()=>{}) Any given `drawFunc` overrides the existing `this.stageStartDraw` method and expects the _next_ method to call once complete: The default `this.draw(ctx)` method is given` this.stageStartDraw(this.draw)-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])Accept a `canvas` node and an optional `draw` function, prepare the stage draw routine. If the `canvas` is given, immediately call `this.prepare(canvas)` to initiate the layer. new StageRender(canvas, ()=>{}) Any given `drawFunc` overrides the existing `this.stageStartDraw` method and expects the _next_ method to call once complete: The default `this.draw(ctx)` method is given` this.stageStartDraw(this.draw)
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])Perform any preparations for this stage instance to run the canvas tools. This includes resolving and measuring the canvas. class MainStage extends Stage { canvas = playspace prepare(target){ super.prepare(target) // ... } } This will run automatically if the canvas is given in the constructor new MainStage(canvas) // _prepared == true Once prepared the stage is essentially ready-to-go. stage = new MainStage() stage.prepare(canvas) stage.update()
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])When using the internal loop drawing the first draw call occurs through this method, calling `firstDraw` once, then changing the internal draw function to the typical `this.draw` If `this.draw` is not a method, `this.update()` is called and the `stopDraw` method is called.
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])A helper function to apply this stage to the animation frame, calling `update()` for every frame. Call once to start the loop. stage = new MainStage() stage.prepare(canvas) stage.loopDraw()
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])+ `alpha`: A boolean value that indicates if the canvas contains an alpha channel. If set to false, the browser now knows that the backdrop is always opaque, which can speed up drawing of transparent content and images. + `colorSpace` Optional: Specifies the color space of the rendering context. Possible values are: "srgb" selects the sRGB color space. (default value) "display-p3" selects the display-p3 color space. + `desynchronized`: A boolean value that hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop. + `willReadFrequently`: A boolean value that indicates whether or not a lot of read-back operations are planned. This will force the use of a software (instead of hardware accelerated) 2D canvas and can save memory when calling getImageData() frequently.
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])inline update per draw. For each call: + all _drawBefore_ methods + all _nextTick_ methods + the `draw` method (mapped through `this._drawFunc`) + all _drawAfter_ methods
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])Run the given function (with context) on the next draw call. This function is very similar to `onDrawBefore`, but only runs _once_. stage.nextTick(function(ctx){ // run next time. stage.runCustomRender(ctx) }) This is useful for performing clearups, or running routines on single action: let v = this.v = new Value(this.p.radius, width, easing) v.doneHandler = ()=>{ // st.switchOut() this.nextTick(this.switchOut.bind(this)) } switchOut() { this.log('doneHandler') this.v = undefined; }
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])The `firstDraw(ctx)` method us used _once_ when drawing starts. This occurs before the first `update()` call is performed. This is useful if you're setting context arguments - but only need to set them once. class Main extends Stage { firstDraw(ctx) { ctx.fillStyle = '#ccc' ctx.font = 'normal 1em arial' } }
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])The primary rendering function to override. Called by the `update()` method, given the context `ctx` of the target canvas. This is essentially the same as running the update function manually: const ctx = canvas.getContext('2d'); const stage = new MainStage() stage.prepare(canvas) function draw() { // or: stage.clear(ctx) ctx.clearRect(0, 0, canvas.width, canvas.height); // Run the draw routines stage.draw(ctx) // And rinse repeat. requestAnimationFrame(draw); } draw()
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])Perform a standard 'clearRect' using the cached dimensions of the canvas. stage.clear(ctx) Synonymous to: const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); Apply an optional flood fillStyle: stage.clear(ctx, '#000')
ClassDeclaration