fatfattymcfat Posted February 17, 2014 Share Posted February 17, 2014 Hey all, just started working with Phaser today and it's great fun. I've become stuck trying to destroy a sprite when it hits a wall. Something like this works quite well for colliding and stopping against a wall: game.physics.collide(mobs, walls); And something like this is great for killing mobs when they hit a bullet: game.physics.overlap(mobs, bulletGroup, killMob, null, this); But the same overlap callbacks don't seem to work when I'm comparing a wall to a group. For instance, this doesn't work: game.physics.overlap(wall, bulletGroup, killBullet, null, this); In this case, the walls are: walls = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 1); Looking forward to carrying on with the project!Cheers Link to comment Share on other sites More sharing options...
Zenryo Posted February 17, 2014 Share Posted February 17, 2014 I have the same problem. If a moving element hits the left side of the screen I want it to be removed. Thanks! fatfattymcfat 1 Link to comment Share on other sites More sharing options...
fatfattymcfat Posted February 17, 2014 Author Share Posted February 17, 2014 I solved this in a really hacky way: if (bulletGroup.length >= 1) { game.physics.collide(bulletGroup, walls); } And: bulletGroup.forEach(function (bullet) { if (bullet.body.velocity.x == 0 && bullet.body.velocity.y == 0) { bullet.kill(); } }) This way they stop if they hit a wall and they're killed if they stop. There must be a better way to do this? Zenryo 1 Link to comment Share on other sites More sharing options...
Recommended Posts