【发布时间】:2020-08-21 23:54:27
【问题描述】:
我正在尝试使用 Cocos Creator 创建游戏。我在游戏中使用了多个文件。比如Game.jsGameOver.jsJump.js等。我正在用GainScore.js收集分数。我必须将最终分数发送到GameOver.js 文件。我在比赛中正确显示比分。但是当游戏结束时,我必须将其发送到另一个屏幕。如何将游戏分数用作全局?
我的 gainScore 函数:
gainScore() {
this.score += 1;
if (this.scoreDisplay === null) return;
this.scoreDisplay.string = this.score;
},
我的GameOver.js 文件
cc.Class({
extends: cc.Component,
properties: {
scoreEnd: {
default: null,
type: cc.Label,
},
},
start() {
this.scoreEnd.string = this.score.toString(); // I can't access with this way
},
});
【问题讨论】:
标签: cocos2d-js