+ 1

Javascript Classes

I am using p5.js to make a game for a course, we have been given code to make basic collision detection. I was hoping to break the shapes up into there individual lines for a more advance collision detection system. My main focus is around the shapes class as I can draw to the canvas however when I introduce a new primitive such as lines it seems to use a completely seperate shapes object. is there a way I should code this? https://code.sololearn.com/W1jya5Lo3Kog/#html

13th Sep 2020, 8:51 PM
Charlie Crease-huggett
1 Antwort
+ 1
I think you forgot to `translate(x, y)` after drawing, in this case, a line. If you draw a line from 0, 0 to 200, 250, then you would have to translate to 200, 250. I would write this is the existing function `drawLine`, and add an optional boolean parameters that says weather to translate or not (defaults to true)
17th Sep 2020, 10:27 AM
Martín Stanicio