P2 sprite collision group pain

Recommended Posts

Hi all,

Been banging my head against the wall for ages with this.

Default P2 collision works, I clearShapes() on each sprite to get rid of these boundary boxes and loadPolygon() to get my custom boundaries (defined in sprite_physics.json). However the collision groups appear not to be working as my player sprite goes straight through/under the enemy.

Can anyone see where I'm going wrong?


// in index.html
(function() {
    var game = new Phaser.Game(1024, 768, Phaser.AUTO, null)
    game.state.add('Game', Game);

// in game.js
var Game = function (game) {

Game.prototype = {

    preload: function () {'player', 'assets/player.png');'enemy', 'assets/enemy.png');'sprite_physics', 'assets/sprite_physics.json');

    create: function () {;

        this.playerCollisionGroup =;
        this.enemyCollisionGroup =;


    update: function () {
        // <snip> do some steering stuff </snip>

    createPlayer: function () {
        this.player =, + 300, 'player');, true); // so I can see the polygon's boundaries

        // Gets rid of current bounding box
        // BUT THEN need to add collision cos default p2 collision is wiped with clearShapes()

        // Add boundary shape from PhysicsEditor
        this.player.body.loadPolygon('sprite_physics', 'player');

        // Seems to do nothing :(

    createEnemy: function () {
        this.enemy =,, 'enemy');, true);


        this.enemy.body.loadPolygon('sprite_physics', 'enemy');



Share this post

Link to post
Share on other sites


I just downloaded phaser.min.js 2.9.1 and it fixed everything.

I'm kind of pissed off I spent that much time trying to figure something out when it was a massive live defect but I'm mostly grateful for this community (you, Samid737) and phaser's library working with a patch. I would recommend the Phaser team to be more vocal with their fundamental hotfixes....

Or am I missing something in terms of their release exposure?




Share this post

Link to post
Share on other sites

Ironically, I introduced the bug. The complete story #279, The underlying problem is yet to be resolved, but its not A critical one. This was an unexpected bug as you can see. The Phaser-CE community does its best to foresee and are pretty busy maintaining, but quality control is definitely an added challenge with community driven projects.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.