I'm working on a game with some monsters of different kinds (one kind = one subclass of SKSpriteNode) crossing the scene. To each kind is given a specific sound.
One example is I can have at a specific point in time:
- 5 monsters A
- 2 monsters B
- 0 monster C
What I would like at any time, is to loop a sound for each class which is part of the scene (A, B) (and not for each sprite !) , and to stop playing a sound for each class absent from the scene(C).
My first idea was to store a specific sound into each class of monster and to add a SKAction to each sprite that would play loop the sound of its class. But this would play loop as many sounds as sprites on scene, and this doesn't match with my expectations.
Do you have an idea on the best approach to adopt for this ? Is there a possibility to implement a kind of observer that would be able to notify when an instance of class is on the scene and when it is not ?
Many thanks for your help !