【发布时间】:2020-10-18 23:51:04
【问题描述】:
我正在使用 Phaser 3 和 javascript 开发一个拼字游戏。到目前为止,我已经能够通过单击按钮在屏幕上显示一个打乱的单词。现在我需要用户能够点击他们认为是被打乱的单词的第一个字母。如果他们是对的,那么这个字母就会被放在被打乱的单词上方的某个地方,然后他们会继续这样做,直到单词被正确拼出。如果他们点击了错误的字母,它不会被放在上面,所以他们再试一次。我不知道下一步该做什么。到目前为止,这是我所拥有的:
public onSceneCreated() {
// Fit world to screen
this.scene.game.scale.scaleMode = Phaser.Scale.FIT;
this.scene.game.scale.refresh(PhaserHelper.worldSize.width, PhaserHelper.worldSize.height);
// See the world size, eventually remove
this.scene.cameras.main.setBackgroundColor("rgba(255, 255, 255, 0.2)");
let centerX = PhaserHelper.worldSize.width / 2;
let centerY = PhaserHelper.worldSize.height / 2;
// Random word picked from array
let word = this.activityItems[Math.floor(Math.random() * this.activityItems.length)];
// Function that scrambles a word
let scramble = (a) => {
a = a.split("");
for(let b = a.length - 1; 0 < b; b--) {
let c = Math.floor(Math.random()*(b + 1));
let d = a[b];
a[b] = a[c];
a[c] = d;
}
return a.join("");
}
// Adds button (clickable text)
let clickButton = this.scene.add.text(1000, 800, 'Button', {
fontFamily: Fonts.BalsamiqSans,
fontSize: 50,
color: Colors.black,
});
clickButton.setInteractive();
// Display scrambled word by clicking button
clickButton.on('pointerdown', () => {
this.scene.add.text(centerX, centerY, scramble(`${word.answer.text}`), {
fontFamily: Fonts.BalsamiqSans,
fontSize: 100,
color: Colors.black,
});
});
console.log(`${word.answer.text}`);
}
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: javascript phaser-framework