brianzinn Posted April 17, 2017 Share Posted April 17, 2017 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 17, 2017 Share Posted April 17, 2017 Just cast it like this: let textureContext:CanvasRenderingContext2D = <any>planeTexture.getContext() brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.