thre Posted April 1, 2022 Share Posted April 1, 2022 Been staring at this for hours, seen few tutorials and can't find the error. Can someone give me some direction. I believe this is suppose to let me draw but its doesn't. const canvas = document.querySelector("#canvas"); const ctx = canvas.getContext("2d"); canvas.height = window.innerHeight; canvas.width = window.innerWidth; let painting = false; function start(){ painting = true; } function end(){ painting = false; } function draw(e){ if (!painting) return; ctx.lineWidth = 10; ctx.lineCap = "round"; ctx.lineTo(e.clientX, e.clinetY) ctx.stroke(); } canvas.addEventListener("mousedown", start); canvas.addEventListener("mouseup", end); canvas.addEventListener("mousemove", draw); Link to comment Share on other sites More sharing options...
Ingolme Posted April 1, 2022 Share Posted April 1, 2022 It looks like you're missing a ctx.beginPath() call. It should go right above the lineTo() call. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now