We help IT Professionals succeed at work.
Get Started

My Javascript Phaser Udemy Game example needs some suggestions to fire-up

164 Views
Last Modified: 2020-01-14
Hi
In a Udemy video lecture on 'building games with phaser', the instructor is working w the following 'ColorZap' project code zip below..
He is using brackets for an IDE, so so am I:

My XAMPP serves the files correctly, no problem, in Safari.

So, he has a main.js that tries to start the game object.

main.js :
var game;
//var score;
//var soundOn = true;

window.onload = function () {
    if (screen.width > 1500) {
        //desktop laptop
        game = new Phaser.Game(480, 640, Phaser.AUTO, "ph_game");

    } else {
        //mobile device
        game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, "ph_game");
    }
    //add a state or screen to the game
    game.state.add("StateMain", StateMain);
    game.state.add("StateTitle", StateTitle);
    game.state.start("StateTitle");

}

Open in new window


But, the Problems console claims:

"Missing 'use strict' statement    if (screen.width > 1500) {

but most notably: Phaser was used before it was defined. . game = new Phaser.Game(480, 640, Phaser.AUTO, "ph_game");

which puzzles me, because where are the lines of code in his example or way this can work? I wrote the code from the Udemy vid. I can't imagine I left something off.

These project files are attached also. What could I not have done? Where do I define Phaser for it? Is there a  #include equivalent?
A black rectangle appears in the browser to test the code, so I know the size of the program area is being registered properly.

Thanks
colorZap-copy.zip
Comment
Watch Question
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE