0

Currently my code plays a sound when there is contact between any objects in my game using andEngine and Box2D and the walls, the problem I have is that when contact is made with any objects it starts again I understand why this is happening. What I want to do if possible is keep playing the sound while also playing it for another collision. I think I may need to use threads but I am unsure how to do this in java for android.

@Override
public void beginContact(Contact contact)
{
    Rattle.this.mExplosionSound.play();
}

UPDATE: I don't seem to have been able to fix the issue but I know that what I need to do is play this sound multiple times simultaneously, I have tried threads and the soundPool but got no luck with either still not sure what to do.

bobthemac
  • 1,172
  • 6
  • 26
  • 59

2 Answers2

1

It seems you have only one instance of the sound. Then you call play on the same sound twice, therefore it stops playing and starts from the beginning.

Imagine having one CD player - you press play, the music starts to play. You press play again and the player starts reading the track from the beginning. What you need is two players, therefore you may need two instances of the same sound.

(I don't have much experience with sound on Android so I may be wrong, please take the advice with a grain of salt.)

JohnEye
  • 6,436
  • 4
  • 41
  • 67
-1

Even I was developing a game some time back and I found a similar problem. You should use SoundPool to play short sounds like crashing and collisions. here are some good linkswhich helped me. Link 1, link 2.

Antrromet
  • 15,294
  • 10
  • 60
  • 75