Jump to content

Getting started with Phaser - physics not loaded

Recommended Posts

Hi there,


I'm trying to get off the ground with creating my own phaser games, but I've hit a blocker that I just can't work out. I have a very basic setup, based on the Phaser Tutorial examples:

  • index.html
  • js
    • phaser.min.js
  • assets
    • starfield.png

This is my very, very basic index.html code - but it falls over at the first hurdle when I try to access a game.physics method:

<!doctype html><html>    <head>        <meta charset="UTF-8" />        <title>hello phaser!</title>        <script type="text/javascript" src="js/phaser.min.js"></script>    </head>    <body>    <script type="text/javascript">    window.onload = function() {        var game = new Phaser.Game(1900, 1000, Phaser.AUTO, '', { preload: preload, create: create });        function preload () {            game.load.image('starfield', 'assets/starfield.png');        }        function create () {            game.physics.startSystem(Phaser.Physics.ARCADE);            //  The scrolling starfield background            starfield = game.add.tileSprite(0, 0, 1900, 1000, 'starfield');        }    };    </script>    </body></html>

In Chrome I get the following error:


  1. Uncaught TypeError: Object #<Object> has no method 'enable' (index):48
    1. d.StateManager.loadCompletephaser.min.js:4
    2. d.Game.loadCompletephaser.min.js:5
    3. d.SignalBinding.executephaser.min.js:4
    4. d.Signal.dispatchphaser.min.js:4
    5. d.Loader.nextFilephaser.min.js:10
    6. d.Loader.fileCompletephaser.min.js:9
    7. a.data.onloadphaser.min.js:9

This is all running locally under Apache.


I have tried a few other basic things, but whenever I try to access any Phaser object methods I get this same 'Uncaught TypeError' issue.


I have phaser-examples set up locally, and these run just fine - as do the Phaser Tutorial examples. I have been trying to just build out from the tutorials to experiment and get to grips with everything. I assume it's a really dumb error, but I just can't see where I'm going wrong.


Any tips would be gratefully accepted.




Link to post
Share on other sites

I cloned Phaser from Github. You're absolutely right, though - somehow I had v1.1.3 instead of v2 in my test game. I must have picked it up from one of the examples I was toying with. Switching to v2 has fixed everything - we have physics! Thank you.


Out of interest, I have seen comments suggesting using Gruntfile.js to build from - but I'm not clear what to do with that. 


Run `grunt` to perform a default build to the `dist` folder and update the examples.


Is it just a case of loading this file in a browser?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...