新手文档,制作第一个游戏,成一个星星无法实现

onLoad () {
// 获取地平面的 y 轴坐标
this.groundY = this.ground.y + this.ground.height/2;
// 生成一个新的星星
this.spawnNewStar();

},


spawnNewStar: function() {
// 使用给定的模板在场景中生成一个新节点
var newStar = cc.instantiate(this.starPrefab);
// 将新增的节点添加到 Canvas 节点下面
this.node.addChild(newStar);
// 为星星设置一个随机位置
newStar.setPosition(this.getNewStarPosition());

},

getNewStarPosition: function () {
    var randX = 0;
    // 根据地平面位置和主角跳跃高度,随机得到一个星星的 y 坐标
    var randY = this.groundY + Math.random() * this.player.getComponent('Player').jumpHeight + 50;
    // 根据屏幕宽度,随机得到一个星星 x 坐标
    var maxX = this.node.width/2;
    randX = (Math.random() - 0.5) * 2 * maxX;
    // 返回星星坐标
    return cc.v2(randX, randY);
},

这个歌我在文档中复制下来后,只要一输入 this.spawnNewStar();这句话,就无法载入游戏界面,麻烦帮忙查看下

1赞

大小写区分了吗

onLoad 后面少了:function
onLoad: function () {
//…
}