我通常是python家伙,尽管JavaScript并不是我的新手,但是Phaser游戏库却是。我正在尝试使用Phaser制作射箭游戏,尽管我的游戏文件不完整,但据我所知,此文件至少应加载背景图片。有人可以帮我弄清楚为什么它不加载任何东西吗?如果有帮助,我正在使用VSCode的实时服务器扩展来加载它。
索引HTML文件
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>Game</Title>
<script type = "text/javascript" src = "phaser.min.js"></script>
</head>
<body><script type="text/javascript" src="archery_game.js"></script></body>
</html>
游戏文件
const game = new Phaser.game(800, 600, Phaser.AUTO, '', {
preload: preload,
create: create,
update: update })
//Variables
let score = 0
let scoreText
let arrows
let player
function preload() {
//Load and define our images
game.load.image('archer', 'archer.png')
game.load.image('sky', 'sky.png')
game.load.image('ground', 'platform.png')
game.load.image('target', 'archery_target.png')
}
function create() {
//Implement physics
game.physics.startSystem(Phaser.physics.ARCADE)
//Add the sky sprite
game.add.sprite(0, 0, 'sky')
//Create the ground
platforms = game.add.group()
platforms.enableBody = true
let ground = platforms.create(0, game.world.height - 64, 'ground')
ground.scale.setTo(2, 2)
}
function update() {
//Update physics
}
答案 0 :(得分:2)
您需要大写Game构造函数:
const game = new Phaser.game(800, 600...
应该是
const game = new Phaser.Game(800, 600...