Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: CanvasRenderingContext2D
Source: JSObjects/OffscreenCanvasRenderingContext2D.cs
MDN Reference: OffscreenCanvasRenderingContext2D on MDN
The OffscreenCanvasRenderingContext2D interface is a CanvasRenderingContext2D rendering context for drawing to the bitmap of an OffscreenCanvas object. It is similar to the CanvasRenderingContext2D object, with the following differences: https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvasRenderingContext2D
| Signature | Description |
|---|---|
OffscreenCanvasRenderingContext2D(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Method | Return Type | Description |
|---|---|---|
Commit() |
void |
Pushes the rendered image to the context's OffscreenCanvas object's placeholder canvas element. ⚠ Deprecated - Not for use in new websites |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<OffscreenCanvasRenderingContext2D>(...)or constructornew OffscreenCanvasRenderingContext2D(...)
const canvas = document.getElementById("canvas");
const offscreen = canvas.transferControlToOffscreen();
const worker = new Worker("worker.js");
worker.postMessage({ canvas: offscreen }, [offscreen]);onmessage = (event) => {
const canvas = event.data.canvas;
const offCtx = canvas.getContext("2d");
// draw to the offscreen canvas context
offCtx.fillStyle = "red";
offCtx.fillRect(0, 0, 100, 100);
};