eloguvnah Posted January 25, 2014 Share Posted January 25, 2014 So I'm closer to figuring out why when I call the kill function on a laser hitting an enemy, the enemy disappears and not the laser. It's because it seems like the collide function is reversing the arguments depending on whether the lasers colliding with another sprite or if it's colliding with a tile. It's really weird. Laser.prototype.update = function() {game.physics.collide(this._laserGroup, layer, laserLayerCollideHandler, null, this);game.physics.collide(this._laserGroup, jumperBot._sprite, laserJumperBotCollideHandler, null ,this);game.physics.collide(this._laserGroup, turret._turret1Base, laserTurretCollideHandler, null ,this);} // end updatefunction laserLayerCollideHandler(laser, layer) {laserExplode(laser, layer, this);//laser.kill();console.log(laser);}function laserJumperBotCollideHandler(laser, jumperBot) {laserExplode(laser, jumperBot, this);//laser.kill();//console.log(jumperBot);}function laserTurretCollideHandler(laser, turret) {laserExplode(laser, turret, this);//laser.kill();//console.log(laser);}function laserExplode(laser, target, context) {if ( laser.body.touching.right ) {context._laserEmitter.x = laser.x + (laser.body.width );context._laserEmitter.y = laser.y;context._laserEmitter.maxParticleSpeed.x = -550;context._laserEmitter.start(true, 200, null, 5);} else if ( laser.body.touching.left ) {context._laserEmitter.x = laser.x;context._laserEmitter.y = laser.y;context._laserEmitter.maxParticleSpeed.x = 550;context._laserEmitter.start(true, 200, null, 5);}// var getIndex = context._laserGroup.getIndex(laser);// console.log(getIndex);// context._laserGroup.remove(getIndex);}If I set laser.kill() on the function handling collisions between the laser and the tile, the laser dies no prob, but in the collision with jumperBot or turret, it's the jumperBot or turret that's being killed. Does anyone know what's going on here?I could just make a separate collision handler for sprites vs. tilemap but that seems weird to me. Link to comment Share on other sites More sharing options...
Recommended Posts