eaglehopes Posted August 18, 2022 Share Posted August 18, 2022 (edited) Hi, I am preparing a canvas program. I prepared a code for drawing lines by below code : draw(g,x0,y0,x1,y1) { // draw line on canvas g.save(); g.strokeStyle = "red"; g.lineWidth = 1; g.moveTo(x0,y0); g.lineTo(x1,y1); g.stroke(); // go back to origin 0,0 coordinates gotoOrigin(); g.restore(); } Although I used save() and restore() methods above, after this method, all strokes become red eventhough I explicitly changed strokeStyle to "#000000". I need some help about what is my mistake? Thanks. Edited August 18, 2022 by eaglehopes add comment to code to clarify Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted August 19, 2022 Solution Share Posted August 19, 2022 You need to use beginPath() before you start to draw something. Add a call to beginPath after you save the context. 1 Quote Link to comment Share on other sites More sharing options...
eaglehopes Posted August 19, 2022 Author Share Posted August 19, 2022 @kicken, thank you very much. 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.