Jump to content

Trouble with P2JS physics


Hive64
 Share

Recommended Posts

Okay I must be doing something stupid.  I keep getting the error "Uncaught TypeError: Cannot read property 'p2' of undefined" on line 25 of the following code;

var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', {	preload: preload,	create: create,	update: update});function preload() {	game.load.spritesheet('dude', 'assets/dude.png', 32, 48);}var player, sprite;var players;var GRID_SIZE = 32;function create() {	//Enable p2 physics	game.physics.startSystem(Phaser.Physics.P2JS);	player = game.add.sprite(200, 200, 'dude');	//enable physics	game.phsysics.p2.enableBody(player);	player.body.setZeroDamping();	player.body.fixedRotation = true;}function update() {	}function movePlayer(x, y) {	player.x += x * GRID_SIZE;	player.y += y * GRID_SIZE;}

From what i understand, the order is: create game (line 1), start the physics type of my choice (line 20), then enable that physics on the sprite that I created (line 25).  I'm a newbie so any tips are more than welcome!!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...