pb_ Posted February 16, 2015 Share Posted February 16, 2015 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 More sharing options...
rich Posted February 17, 2015 Share Posted February 17, 2015 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! pb_ 1 Link to comment Share on other sites More sharing options...
pb_ Posted February 17, 2015 Author Share Posted February 17, 2015 Hi Rich, Thanks for the reply. That worked perfectly. Thanks a bunch. Link to comment Share on other sites More sharing options...
Recommended Posts