Create a Texture with Canvas2D
If you need to create textures at runtime to paint on dynamically, you may want to make use of
CanvasRenderingContext2D,
which is the Browsers set of 2D drawing methods on the <canvas>
element.
In Wonderland Engine, you can create a texture from a canvas by simply passing it to the Texture constructor.
Example
Below, you will find the example from the CanvasRenderingContext2D MDN page integrated in Wonderland Engine:
|
|
Updating after Change
After you changed a canvas after creating the initial texture, make sure to update the texture to reflect the changes.
For the above example, you would:
|
|
Provide additional parameters to Texture.update() to update only a subrange for better performance.