javascript - 未捕获的语法错误:意外的令牌 { javaScript
问题描述
import { LoadScene } from "./scenes/LoadScene.js";
在这行代码我得到这个错误:'Uncaught SyntaxError: Unexpected token {'
要将代码部署到浏览器中,我使用了 Visual Studio 代码的扩展“Live Server”。
出现导入的所有代码:
/** @type {import('./../../PHAZER/phaser-3.18.1/types/phaser')} */
import { LoadScene } from "./scenes/LoadScene.js";
import { MenuScene } from "./scenes/MenuScene.js";
let game = new Phaser.Game({
type: Phaser.AUTO,
width: 800,
height: 600,
scene: [
LoadScene, MenuScene
]
});
export const CTS =
{
SCENES: {
LOAD: 'LOAD',
MENU: 'MENU'
}
}
import { CTS } from './../CTS.js';
import { MenuScene } from './MenuScene';
export class LoadScene extends Phaser.Scene
{
constructor(){
super({
key: CTS.SCENES.LOAD
})
}
preload() {
this.load.image("logo", "./../assets/logo.png");
this.load.image('bg', './../assets/title_bg.jpg');
this.load.image('playBt', './../assets/play_button.png');
this.load.image('optionsBt', './../assets/options_button.png');
let loadingBar = this.add.graphics({
fillStyle: {
color: '0xffffff'
}
});
this.load.on('progress', (percent) => {
loadingBar.fillRect(0, this.game.renderer.height/2, this.game.renderer.width * percent, 50);
console.log(percent);
});
}
create() {
console.log('Hello from LoadScene');
this.scene.start(CTS.SCENES.MENU, 'Hello from loadScene');
}
}
import { CTS } from './../CTS.js';
export class MenuScene extends Phaser.Scene
{
constructor(){
super({
key: CTS.SCENES.MENU
})
}
init(){
console.log('MenuScene running!');
}
preload(){
}
create() {
this.add.image(0, 0,"bg");
}
}
和这里的 html 代码,我在其中导入(我猜)phaser.js 这是引擎文件(我猜?到目前为止我只是按照教程进行操作)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My Game</title>
<style type="text/css">
body {
margin: 10;
}
</style>
</head>
<body>
<script src="./phaser.js"></script>
<script src='main.js'></script>
</body>
</html>
当我使用 parcel 做同样的事情时,它可以工作,但我得到了一些其他奇怪的行为,当我使用 http-server 时,它只是下载它应该在我进入页面时运行的 html 文件。
我正在与 Phaser 3 合作
解决方案
推荐阅读
- python - ValueError:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值。如何处理这个错误?
- elasticsearch - Elasticsearch 7.x 搜索空闲慢
- vue.js - 如何将本地文件夹图像(资产)包含到 vue App
- php - php中如何格式化数组
- mysql - ubuntu 18.04 LTS 中未连接 SQL
- javascript - Javascript ES6 更好的方法来循环对象并与多个嵌套对象匹配并返回 id
- svelte - 使用[slug].svelte时如何生成单独的js文件
- javascript - 获取今天之前的所有日期
- reactjs - Webpack-dev-server historyApiFallback 重写子域
- python - 如何获取数组中非零项的索引并使用此索引从另一个数组或列表中获取另一个值