简体   繁体   English

JavaScript Phaser 游戏无法加载?

[英]JavaScript Phaser game doesn't load?

I'm normally a python guy, and although JavaScript isn't completely new to me, the Phaser game library is.我通常是一个 python 人,虽然 JavaScript 对我来说并不是全新的,但 Phaser 游戏库是。 I'm trying to make an archery game with Phaser, and although my game file isn't complete, to my knowledge this file should at least load a background image.我正在尝试使用 Phaser 制作射箭游戏,虽然我的游戏文件不完整,但据我所知,该文件至少应该加载背景图像。 Could someone help me figure out why it isn't loading anything?有人可以帮我弄清楚为什么它没有加载任何东西吗? I'm using VSCode's live server extension to load it, if that helps.如果有帮助,我正在使用 VSCode 的实时服务器扩展来加载它。

Index HTML File索引 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>

Game file游戏文件

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

}

You need to capitalize the Game constructor:您需要将 Game 构造函数大写:

const game = new Phaser.game(800, 600...

should be应该

const game = new Phaser.Game(800, 600...

See https://phaser.io/docs/2.6.2/Phaser.Game.htmlhttps://phaser.io/docs/2.6.2/Phaser.Game.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM