As I decided, this is to create an animation sequence containing the image, sound and delay. Then I can queue them so that I can show the image, and the sound accompanies it, and then switch to another image. I do this with SoundPlayer and a custom view (and not a flipper, although you probably could)
The trick is that you cannot just pause the thread for a delay, you will need to use a handler to send yourself messages to update the user interface in the future.
Here is the handler
handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == NEXT_ITEM_MSG) { showNext(); } else if (msg.what == SEQUENCE_COMPLETE_MSG) {
The showNext () method simply captures the next element in the sequence, updates the image, plays a sound, and then displays a message for the handler to call showNext after the sequence.
private void showNext() { if (mRunning) {
Of course, all this requires you to define and hard-code the delays, but, in my experience, you have to do this for the game anyway. I had many occasions when I wanted the delay to be longer than the sound. Here's a code that actually queues items.
battleSequence.addSequenceItem(R.drawable.brigands, R.raw.beep, 2000); battleSequence.addSequenceItem(R.drawable.black, winning ? R.raw.enemy_hit : R.raw.player_hit, 1500);
With this approach, I can have all kinds of logic for adding animation elements, changing durations, looping animations, etc. It just required some tweaking to get delays.
Hope this helps.
museofwater
source share