Robert Smith
Robert Smith

Reputation: 723

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. 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. 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.

Index HTML File

<!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

}

Upvotes: 1

Views: 723

Answers (1)

user1436782
user1436782

Reputation: 21

You need to capitalize the Game constructor:

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.html

Upvotes: 2

Related Questions