Jump to content

physicsBodyType in breakout game example


MBE007
 Share

Recommended Posts

Hi, im begginer to phaser and i have several questions in my mind.i try to learn phaser from phaser examples and read the codes. in one of examples breakout the author write these codes : 

  game.physics.startSystem(Phaser.Physics.ARCADE);    //  We check bounds collisions against all walls other than the bottom one    game.physics.arcade.checkCollision.down = false;    s = game.add.tileSprite(0, 0, 800, 600, 'starfield');    bricks = game.add.group();    bricks.enableBody = true;    bricks.physicsBodyType = Phaser.Physics.ARCADE;

at first author enable physic system with game.physics.startSystem . but in line 7 author change physic type to arcade for bricks group.why the author do this ? is it important to change type ? if we start physics with sartSystem is it effect on bricks ? if we comment the physicsBodyType is it affect on game?

Link to comment
Share on other sites

The reason is that 'bricks' is a Group. Groups themselves don't have physics bodies, or any physics properties. They are just containers for objects. However they have the ability to create objects, so by setting their physicsBodyType it means any object you then create in them will automatically be an Arcade Physics object. Also you can mix physics engine in a single game. So you could have both P2 and Arcade Physics running together, so this allows you to control which system your objects are using.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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