Jump to content

Collision & overlap detection not firing


pb_
 Share

Recommended Posts

The physics overlap function just doesn't want to detect any overlap between the player sprite and the trap group.

 

In the update function I have added three different methods of detection, neither of which will work.

 

After hours of tinkering with the code, I have finally given up and decided to post here.

 

Any thoughts?

 

Below is the part of the script responsible

$.world = {    create : function(){        $.game.physics.startSystem(Phaser.Physics.ARCADE);        this.map = $.game.add.tilemap('map');        this.map.addTilesetImage('tile_set_1', 'tile_sheet'); //tile_sets.name, image reference        this.ground_layer = this.map.createLayer('Ground Layer'); //layers.name        this.ground_layer.resizeWorld();        this.createTraps(this.map.objects['Traps Layer']);        console.log(this.traps);        this.map.setCollisionBetween(1, 500, true, 'Ground Layer');    },    createTraps : function(traps_layer){        this.traps = $.game.add.group();        this.traps.enableBody = true;        this.traps.physicsBodyType = Phaser.Physics.ARCADE;        // var spike_image = $.game.cache.getImage('spikes');        console.log(traps_layer);        var i = traps_layer.length;        while(i--){            var x    = traps_layer[i].x;            var y    = traps_layer[i].y;            var name = traps_layer[i].name;            var image = $.game.add.sprite(x, y, 'spikes');            image.anchor.setTo(0,1);            $.game.physics.arcade.enable(image);            console.log(image)            $.world.traps.create(image);        }    },    trapCollision : function(player, trap){        console.log('DEAD');    },    update : function(){        $.game.physics.arcade.collide($.player.image, this.ground_layer);        $.game.physics.arcade.overlap($.player.image, $.world.traps, this.trapCollision, null, this);        $.game.physics.arcade.collide($.player.image, $.world.traps, this.trapCollision, null, this);        if($.game.physics.arcade.overlap($.player.image, $.world.traps)){            console.log('asdasdasd');        }    }};
Link to comment
Share on other sites

        while(i--){            var x    = traps_layer[i].x;            var y    = traps_layer[i].y;            var name = traps_layer[i].name;            var image = this.traps.create(x, y, 'spikes');            image.anchor.setTo(0,1);        }

From the looks of it you've created a physics Group (traps) but are then creating the Sprites in the world (game.add.sprite) and then creating another new sprite in the traps Group (traps.create). Try the above and see what happens!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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