Jump to content

Sprite has no body (P2)


Vignarg
 Share

Recommended Posts

I'm going through Interphase and trying to replicate that pool game. The guide says by simply enabling P2 on a sprite, it sets the anchor on the body to .5, but when I compile, the sprite is still halfway off the screen. More, when I uncomment the "body.static = true" portion, I get a console error that there is no body. 

 

I checked the other Phaser examples on p2 basics, and everything seems right. The system is started, the sprite is enabled for it, but these symptoms clearly seem to indicate there's no physics system going on. Any ideas?

 

 

module EightBall {        export class MainGame extends Phaser.Game {               constructor(){             super(800, 600, Phaser.CANVAS, 'game', null, false, true)                    this.state.add('preloader', Preloader, false);            this.state.add('mainMenu', MainMenu, false);            this.state.add('play', Play, false);            this.state.start('preloader');        }    }    export class Preloader extends Phaser.State {        init() {            this.scale.pageAlignHorizontally = true;            this.physics.startSystem(Phaser.Physics.P2JS);             }        preload() {                        this.load.path = 'Assets/';            this.load.images(['table']);            this.load.physics('table');        }        create() {            this.game.state.start('mainMenu');        }            }            export class MainMenu extends Phaser.State {        create() {            this.game.state.start('play');        }    }    export class Play extends Phaser.State {        table: Phaser.Sprite;        create() {            this.table = this.add.sprite(400, 300, 'table');            this.physics.p2.enable('table');          //  this.table.body.static = true;                    }    }         }window.onload = () => {    var game = new EightBall.MainGame();}

 

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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