Jump to content

P2 anchor.set Issue in Sandbox!


flowabuse
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

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