Jump to content

Problem with javascript


Recommended Posts

good day at the problem with the javascript code that I need to run. the code should draw two lines, but why not draw. here's the code, please help if you can.

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title></head><body><canvas id = 'MyCanvas' width = 512 height = 384></canvas><script type="text/javascript"> </script><script>var canvas  = document.getElementById('MyCanvas');var ctx = canvas.getContext('2D');ctx.beginPath();ctx.moveTo(20,20);ctx.lineTo(470, 20);ctx.lineTo(20, 470);ctx.fill();</script></body></html>
Link to comment
Share on other sites

Hello again my dear english-friendly user, 


This forum is dedicated to Babylon.js in particular, and not webgl.

Moreover, if you display the console of your browser (F12 on IE, chrome and Firefox) and look at the errors, you will find this one : 

Uncaught TypeError: Cannot read property 'beginPath' of null 

Try this : 

var ctx = canvas.getContext("2d");

Next time, try to post your question in the good forum :)

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.

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.


  • Recently Browsing   0 members

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