Sign in to follow this  

P2 anchor.set Issue in Sandbox!

Recommended Posts    


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.


Share this post

Link to post
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;;            Platform = function (game, x, y) {     , game, x, y);       =, 0);;, 0x000000, 0.5);      , 0, PLATFORM_WIDTH, PLATFORM_HEIGHT);;                this.anchor.setTo(0.5, 0.5);              ;      , true);    };        Platform.prototype = Object.create(Phaser.Sprite.prototype);    Platform.prototype.constructor = Platform;    Platform.prototype.update = function() {    };                Ball = function (game, x ,y ) {      , game, x, y);       =, 0);;, 0x000000, 0.5);      , 0, BALL_RADIUS);;                this.anchor.setTo(0.5, 0.5);              ;                        //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.

Share this post

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.