There is a small problem at the start of the addBackground()
function. The shape
and cover
variables are mixed up:
var shape = new THREE.PointsMaterial({color: 'white', size: 2});
var cover = new THREE.Geometry();
Shapes are always a kind of “geometry” and covers are always a kind of “material.” So, you can fix the error by switching the two variables:
var cover = new THREE.PointsMaterial({color: 'white', size: 2});
var shape = new THREE.Geometry();
Also, at the bottom of the addBackground()
function, the code currently tries to add the cover to the scene:
var stars = new THREE.Points(shape, cover);
scene.add(cover);
You’ll need to change that to add the stars to the scene instead:
var stars = new THREE.Points(shape, cover);
scene.add(stars);
There is one other small problem in the addBackground()
function. Instead of Math.PI
when computing the declination, the code currently has Math.Pi
(lowercase i
):
var ra = 2 * Math.PI * Math.random();
var dec = 2 * Math.Pi * Math.random();
If you change that so it’s Math.PI
like the right ascension, then the background code will work just fine:
var ra = 2 * Math.PI * Math.random();
var dec = 2 * Math.PI * Math.random();
Let me know if you run into any other problems,
-Chris
Perfect! now everything is working fine!
能不能发一下《倾斜板子游戏》的完整代码?