So recently i thought i figured out a solution for it, only to find out it doesnt work when i have more than one of the same object type added to the level.
What i was doing is iterating through my different list of objects and checking if any of them are colliding with the player, if they are i play the sound for that one colliding with the player and then i set the boolean for the sound to true, meaning the sound has been played now.
When their are no collisions going on or if the current object being iterated isnt colliding with the player i set the sound boolean back to false. So as you probably can see, there is a issue when there is more than one of the same objects added because one of them will set the boolean to false and the sound will be played over and over as long as the player is colliding with one of the objects.
So i have run out of solutions to fix this so i am seeking out help.
Thanks anyone who can offer assistance.
EDIT:
Here is an example of how i am doing it now:
private void checkNeutalSwitchers() {
Iterator<Tile> switcherIT = this.neutralSwitcherTiles.iterator();
while (switcherIT.hasNext()) {
Sprite square_sprite = switcherIT.next();
float distance = MathUtils.distance(playerBoat.getX(),
playerBoat.getY(), square_sprite.getX(), square_sprite.getY());
if (distance < 11) {
if (square_sprite.collidesWith(player)) {
if (square_sprite.getUserData().equals("triangle")) {
playerBoat.detachChild(player);
player = swithcer.getTriangle();
playerBoat.attachChild(player);
if (this.neutralSwitcherBool == false) {
this.neutralSwitcherBool = true;
this.switchShapesSound.play();
}
}
if (square_sprite.getUserData().equals("square")) {
playerBoat.detachChild(player);
player = swithcer.getSquare();
playerBoat.attachChild(player);
if (this.neutralSwitcherBool == false) {
this.neutralSwitcherBool = true;
this.switchShapesSound.play();
}
}
if (square_sprite.getUserData().equals("circle")) {
playerBoat.detachChild(player);
player = swithcer.getCircle();
playerBoat.attachChild(player);
if (this.neutralSwitcherBool == false) {
this.neutralSwitcherBool = true;
this.switchShapesSound.play();
}
}
if (square_sprite.getUserData().equals("rectangle")) {
playerBoat.detachChild(player);
player = swithcer.getRect();
playerBoat.attachChild(player);
if (this.neutralSwitcherBool == false) {
this.neutralSwitcherBool = true;
this.switchShapesSound.play();
}
}
} else {
this.neutralSwitcherBool = false;
}
}
}
}