flowabuse Posted May 22, 2015 Share Posted May 22, 2015 https://phaser.io/sandbox/edit/tpauMNLC When i try to enable p2 physics for a sprite i get Uncaught TypeError: Cannot read property 'set' of undefined.for the object.anchor.set(0.5); of @method Phaser.Physics.P2#enableBody. Please check the link above.Also how do i go about debugging in Sandbox? I have tried putting breakpoints in VM#### but a new one starts everytime i refresh or change something so that didn't work. Link to comment Share on other sites More sharing options...
icp Posted May 23, 2015 Share Posted May 23, 2015 function create() { var SCREEN_WIDTH = 800; var SCREEN_HEIGHT = 600; var PLATFORM_WIDTH = 50; var PLATFORM_HEIGHT = 100; var BALL_RADIUS = 20; this.game.physics.startSystem(Phaser.Physics.P2JS); Platform = function (game, x, y) { Phaser.Sprite.call(this, game, x, y); this.graphics = this.game.add.graphics(0, 0); this.graphics.beginFill(0xFFFFFF); this.graphics.lineStyle(2, 0x000000, 0.5); this.graphics.drawRect(0, 0, PLATFORM_WIDTH, PLATFORM_HEIGHT); this.graphics.endFill(); this.anchor.setTo(0.5, 0.5); this.game.add.existing(this); this.game.physics.p2.enable(this, true); }; Platform.prototype = Object.create(Phaser.Sprite.prototype); Platform.prototype.constructor = Platform; Platform.prototype.update = function() { }; Ball = function (game, x ,y ) { Phaser.Sprite.call(this, game, x, y); this.graphics = this.game.add.graphics(0, 0); this.graphics.beginFill(0xffffff); this.graphics.lineStyle(1, 0x000000, 0.5); this.graphics.drawCircle(0, 0, BALL_RADIUS); this.graphics.endFill(); this.anchor.setTo(0.5, 0.5); this.game.add.existing(this); //game.physics.p2.enable(this, false); }; Ball.prototype = Object.create(Phaser.Sprite.prototype); Ball.prototype.constructor = Ball; Ball.prototype.update = function() { }; //var platform = new Platform(game, 50, 100); var j = 100; for (var i = 10;i < SCREEN_WIDTH*2;i += PLATFORM_WIDTH) { new Platform(game,i,j); j += 10; } var ball = new Ball(game, 50, 50); game.physics.enable(ball, Phaser.Physics.P2JS); //game.physics.p2.enable(ball, false); }In constructor, use this instead of var. Link to comment Share on other sites More sharing options...
flowabuse Posted May 24, 2015 Author Share Posted May 24, 2015 Where should i declare my graphics variable then? Can't get it to work, i'm sorry if it's very obvious and i'm being a nub. Link to comment Share on other sites More sharing options...
flowabuse Posted May 27, 2015 Author Share Posted May 27, 2015 Solved here: http://www.html5gamedevs.com/topic/15562-is-physicsp2enablebody-the-same-as-physicsp2enable/#entry88148 Link to comment Share on other sites More sharing options...
Recommended Posts