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

 Share

  • Recently Browsing   0 members

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