Phaser: Physics.add Error

Created on 15 Jun 2018  路  3Comments  路  Source: photonstorm/phaser

I just learn Phaser vby this: Making your first Phaser 3 game

But when I run it in Chrome, I got an error in Chrome developer tool:
main.js:23
Uncaught TypeError: Cannot read property 'add' of undefined at Scene.Create [as create] (main.js:23) at SceneManager.create (SceneManager.js:612) at SceneManager.loadComplete (SceneManager.js:506) at LoaderPlugin.emit (index.js:183) at LoaderPlugin.loadComplete (LoaderPlugin.js:940) at LoaderPlugin.fileProcessComplete (LoaderPlugin.js:899) at SpriteSheetFile.onProcessComplete (File.js:397) at Image.data.onload (ImageFile.js:132)

The error line is: platforms.create(400, 568, 'ground').setScale(2).refreshBody();
How do solve this problem?

Most helpful comment

That error would actually be the result of the line platforms = this.physics.add.staticGroup(); and the error is saying that it can't find the property add of undefined. Since you are attempting to use scene.physics.add this indicates that scene.physics is undefined, and at that point in the tutorial it actually is supposed to be undefined. If you continue reading the next steps are how to setup the Arcade physics system. The important bit is adding

physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 300 },
            debug: false
        }
    },

to your Game config.

All 3 comments

That error would actually be the result of the line platforms = this.physics.add.staticGroup(); and the error is saying that it can't find the property add of undefined. Since you are attempting to use scene.physics.add this indicates that scene.physics is undefined, and at that point in the tutorial it actually is supposed to be undefined. If you continue reading the next steps are how to setup the Arcade physics system. The important bit is adding

physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 300 },
            debug: false
        }
    },

to your Game config.

@Kasuko Yes, I didn't setting the physics.
Thank you.

I should have continued reading to the next part of the tutorial before running the code. I thought I was using the wrong source code or something.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samme picture samme  路  4Comments

sercand picture sercand  路  3Comments

samme picture samme  路  3Comments

JarLowrey picture JarLowrey  路  4Comments

SKEPDIMI picture SKEPDIMI  路  4Comments