0

I am trying to use two.js to draw a line on the screen using the makeLine() function.
But it just gives an error message saying TypeError: this.scene is undefined.

Can anyone help me fix this issue? Thanks in advance.


Code:
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>connectDots</title>
    <script src="../two.min.js"></script>
</head>
<body>
    <div id="drawings"></div>
    <script src="script.js"></script>
</body>
</html>

script.js

var drawingLocation = document.querySelector("#drawings");
var two = new Two({fullscreen: true}).appendTo(drawingLocation);

var line = new two.makeLine(two.width / 2 - 100, two.height / 2, two.width / 2 + 100, two.height / 2);
line.linewidth = 10;
two.update();
백현민
  • 20
  • 4
  • 1
    You have added new keyword in line 4 script.js, this will cause a problem. You are calling a method, not constructing an object. – Beri Nov 18 '20 at 06:58

1 Answers1

1

Remove new keyword from this line:

var line = two.makeLine(two.width / 2 - 100, two.height / 2, two.width / 2 + 100, two.height / 2);

Here you are trying to call method makeLine on two object. Keyword new would assume that you are calling a constructor to create an object. This may be your problem.

Beri
  • 11,470
  • 4
  • 35
  • 57