我是 Phaser 3 和游戏开发的新手,然后我遇到了问题。我正在尝试重新启动游戏场景,但是当我运行它时出现错误消息“Uncaught TypeError: this.scene.restart is not a function”
var playbtn = this.add.dom(390, 600).createFromCache('play-btn');
playbtn.setPerspective(600);
playbtn.addListener('click');
playbtn.on('click', function (event) {
this.scene.restart();
});
这是我的全部代码
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 10</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.24.1/dist/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
dom: {
createContainer: true
},
scene: {
preload: preload,
create: create,
update: update,
hitbomb: hitBomb
}
};
var game = new Phaser.Game(config);
var player;
var stars;
var bombs;
var platforms;
var cursors;
var score = 0;
var gameOver = false;
var scoreText;
var level_state;
var level = 1;
var de_star = 0;
var element;
var playbtn;
function preload ()
{
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.image('star', 'assets/bomb.png');
this.load.image('bomb', 'assets/star.png');
this.load.spritesheet('dude', 'assets/dude.png', { frameWidth: 32, frameHeight: 48 });
this.load.html('play-btn', 'assets/play.html');
this.load.html('nameform', 'assets/loginform.html');
}
当角色击中炸弹时,“再玩一次”按钮会弹出,如果玩家点击该按钮,游戏将重新开始。这些是我的目标......我正在从事的项目是一个教程示例,但任何建议或解决方案都会对我有很大帮助。谢谢
神不在的星期二
慕标琳琳
相关分类