Jump to content

Solved: CanvasRenderingContext2D from DynamicTexture


brianzinn
 Share

Recommended Posts

I am converting my BabylonJS project to Typescript.  Having trouble with one conversion:

With the following code:

var planeTexture = new DynamicTexture('dynamic texture', 512, scene, true)
let textureContext = planeTexture.getContext()

planeTexture.getContext() calls this._canvas.getContext("2d") as you can see here (line 36 /src/Materials/Textures/babylon.dynamicTexture.ts).

Returning actually one of these I am assuming: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D

In BabylonJS, however, it looks like an interface with just a few properties (line 77: /src/babylon.mixins.ts).

So, my problem is that my project won't compile if I want to call methods not in the mixin and I can't seem to cast to CanvasRenderingContext2D (since first property on CanvasRenderingContext2D 'canvas' is missing).  I'd like to call save(), restore(), fillStyle, etc.  It was working in javascript, but does anybody know how to do that in Typescript?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...