ISOmetric Posted December 21, 2016 Share Posted December 21, 2016 I have two groups of sprites, lets call them locks and slots, and each slot has a custom parameter, lets call it slot.locked. I want to implement functionality whereby when any one of the locks is overlapping a slot, the variable slot.locked becomes true, which I managed to implement as follows: function update() { game.physics.arcade.overlap(locks, slots, lockOverlap); } function lockOverlap(lock, slot) { slot.locked = true; } But now I want to have a situation in which whenever a lock is NOT overlapping a slot, the parameter slot.locked becomes false again. Any ideas? Thanks. Link to comment Share on other sites More sharing options...
samme Posted December 22, 2016 Share Posted December 22, 2016 Link to comment Share on other sites More sharing options...
ISOmetric Posted December 27, 2016 Author Share Posted December 27, 2016 I'm not sure how I would be able to use this in to context of the update function. Would I have to check every sprite in locks against every sprite in slots continually, using something like forEach? Link to comment Share on other sites More sharing options...
samme Posted December 29, 2016 Share Posted December 29, 2016 Is it more important that you know when a slot becomes unlocked or just that it gets unlocked again somehow? In the first case, you would loop through the slots (only) after the overlap check: game.physics.arcade.overlap(locks, slots, lockOverlap); slots.forEach(function (slot){ if (!slot.body.wasTouching.none && slot.body.touching.none) { // This slot just became unlocked } }); In the second case, you can just reset all the locks before the overlap check: slots.setAll('locked', false); game.physics.arcade.overlap(locks, slots, lockOverlap); Link to comment Share on other sites More sharing options...
Recommended Posts