Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Phaser is not defined

A topic by Gingarius created Oct 07, 2018 Views: 1,897 Replies: 3
Viewing posts 1 to 3

Hello everyone,

This is my first time joining an event and I am extremely excited. However on the very first step I am hitting a road block. The html loads fine but it seems to grab both of the files. However, my main.js isn't interacting with the phaser.min.js at all which means it basically does nothing. I can't get any work until this is figured out so I hope this isn't too hard. I've attached the HTML and the folder directory as that would be the cause most likely but I can't figure out what is going on. Thanks to anyone and everyone who can help.



Hi Gingarius. Do you have a repo somewhere with all your files?

I recommend opening the inspector (shift + ctrl + i) and looking at the "console" tab. It should show you any errors. You can also look at the "network" tab and refresh the page to ensure that both files are being imported.

I'm guessing there is a bug in your actual main.js file.

Hello!

Here is my repo with everything. I've tried everything and I can't figure it out the code I have right now is mostly skeleton/example code so I don't think it could be me. No errors ever pop up besides 'Phaser is not defined'

https://github.com/Hjwallace/RocketSpam

So in the console I'm not seeing "Phaser is not defined", I'm seeing this (on page load):

TypeError: game.state is undefined[Learn More] main.js:63:1
    <anonymous> file:///home/alex/Downloads/RocketSpam/main.js:63:1
Okay. You have defined "game" in the line above, but it doesn't have a property called "state". I can check that by typing "game" into the console and hitting enter. I can then expand the arrow to see the full "game" object including all its properties.


So for example, "game.anims" exists. "game.config" exists. etc. But no "game.state". Why?

In the docs for Phaser 2.6.2 it does appear that "game.state" should exist. However, in the console it also shows this message when the page loads:

     Phaser v3.14.0 (WebGL | Web Audio)  https://phaser.io

I can see we're using Phaser 3.14. Looking at the 3.14 docs for "Game", I cannot find any mention of "game.state". I'm guessing that Phaser 3 works differently.

My guess is that you're following a tutorial or guide that assumes you're working with Phaser 2, but you actually have Phaser 3 installed. I've never used Phaser before so I can't tell you specifically what you need to do to make it work, but maybe you can find a Phaser 3 tutorial instead.