javascript - 向 Phaser 3 游戏添加场景不起作用
问题描述
因此,我尝试将场景添加到我的 Phaser 3 game.js 文件中(您可以在此处查看代码,也可以在此处查看(非常多的测试版)操作),
根据
let gameScene = new Phaser.Scene('Game');
和
gameScene.preload = function() {
此处描述的方法并通过以下方式启动它们
var game = new Phaser.Game(800,800, Phaser.AUTO, 'game-div', {Game});
这只导致黑屏。
基本上,我想通过使用场景创建一个开始菜单和一个游戏结束菜单。非常感谢上述用于添加场景或创建简单菜单的方法的任何轻量级替代方法!
解决方案
在 中config.scene
,使用以对象为场景的数组。
var scene1 = {
key:'scene1_start_screen', preload: function(){}, create: function(){
//start sceen create, call next scene with
phaser_game.scene.start('scene2_game_screen');
//stop this scene with
phaser_game.scene.stop('scene1_start_screen');
},
}
var scene2 = {
key:'scene2_game_screen',preload: function(){}, create: function(){},
}
var config = {
type: Phaser.AUTO,
width: 600,
height: 600,
backgroundColor: "#b9eaff",
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
parent: 'game',
scene: [scene1,scene2]
};
推荐阅读
- rest - 使用 Camel 调用 REST API,需要对令牌进行单独的身份验证请求
- laravel - 使接受 Laravel 中所需的条款和条件字段
- typescript - 如何在打字稿声明文件中导入 node_module 类型?
- transactions - 每笔交易和购买 1% - 智能合约
- dataframe - 如何总结pandas DataFrame中的列
- load-balancing - 基于 HAProxy 中后端统计的负载均衡
- google-cloud-platform - 将 BigQuery 行级安全性与服务帐号结合使用
- scikit-learn - roc_auc_score 用于不平衡类
- arrays - 读取excel文件并将其映射到反应数组中后,为什么最后一个值总是未定义
- json - DataType.fromJson() 错误:java.lang.IllegalArgumentException:无法将 JSON 字符串“int”转换为数据类型