Paper.js遇到很多问题。在Udemy上做Colt Steele的Web Developer Bootcamp。我在第19节。目前正在尝试制作Patatap克隆。在我被困的时候:
http://codepen.io/SlouchingToast/pen/LWLXYZ
HTML
<!DOCTYPE html>
<html>
<head>
<title>Circles</title>
<link rel="stylesheet" type="text/css" href="circles.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.10.3/paper-full.min.js"></script>
<script type="text/paperscript" canvas="myCanvas">
function onKeyDown(event) {
var maxPoint = new Point(view.size.width, view.size.height);
var randomPoint = Point.random();
var point = maxPoint * randomPoint;
new Path.Circle(point, 10).fillColor = "olive";
}
var animatedCircle = new Path.Circle(new Point(300,300), 100);
animatedCircle.fillColor = "red";
}
</script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>
CSS
canvas {
width: 100%;
height: 100%;
background: black;
}
body, html {
height: 100%;
margin: 0;
}
Chrome控制台错误
Uncaught ReferenceError: animatedCircle is not defined
at at.paper._execute (<anonymous>:11:2)
at u (paper-full.min.js:38)
at HTMLCollection.l (paper-full.min.js:38)
at HTMLCollection.l (paper-full.min.js:32)
at Function.f [as each] (paper-full.min.js:32)
at f (paper-full.min.js:38)
paper._execute @ VM519:11
u @ paper-full.min.js:38
l @ paper-full.min.js:38
l @ paper-full.min.js:32
f @ paper-full.min.js:32
f @ paper-full.min.js:38
应该发生什么,只是显示一个圆圈。那就是它。
答案 0 :(得分:1)
通过将稿件替换为下面,它可行。
首先,删除不必要的结束标记}
。
其次,将animateCircle
修复为animatedCircle
。
<script type="text/paperscript" canvas="myCanvas">
function onKeyDown(event) {
var maxPoint = new Point(view.size.width, view.size.height);
var randomPoint = Point.random();
var point = maxPoint * randomPoint;
new Path.Circle(point, 10).fillColor = "olive";
}
var animatedCircle = new Path.Circle(new Point(300,300), 100);
animatedCircle.fillColor = "red";
</script>