Multiple actors registering touch
I haven't seen a tutorial on this so far, but maybe someone can point me to one.
Say I'm making a whack a mole game. If my player misses, I want to play an animation and sound to acknowledge they missed. If they hit a mole, then I want the mole to react and for there to be a different animation played on it, and a different sound.
So far, my moles will react properly, but when I drop in the behavior onto the background that when it receives a touch, to play the sound, it pretty much always plays, regardless of whether I hit a mole or hit just the background.
Essentially, I want to know a smooth way of ensuring that only one enemy is hit, or the background is hit. It'll never be the case that both should register a touch in this game. Any help is greatly appreciated. I'm doing a big presentation on GS in my company tomorrow and getting this game working perfectly would go a long, long way.
Say I'm making a whack a mole game. If my player misses, I want to play an animation and sound to acknowledge they missed. If they hit a mole, then I want the mole to react and for there to be a different animation played on it, and a different sound.
So far, my moles will react properly, but when I drop in the behavior onto the background that when it receives a touch, to play the sound, it pretty much always plays, regardless of whether I hit a mole or hit just the background.
Essentially, I want to know a smooth way of ensuring that only one enemy is hit, or the background is hit. It'll never be the case that both should register a touch in this game. Any help is greatly appreciated. I'm doing a big presentation on GS in my company tomorrow and getting this game working perfectly would go a long, long way.
Comments
Since you can't have two things being touched at once, put a game level variable that is IsMoleHit.
Make the BG object only do the sound if it's hit AND IsMoleHit=0.
Every time a mole is hit, make the IsMoleHit 1, and every time a mole touch is released, turn it to 0.
I don't have my mac right here or I'd show you the code.
if there is a timing issue with that (since they are both assigned at the same time), the dirty shortcut is to delay the fail sound by like .5
The other way that comes to mind is to only play sounds from the BG. Because if the moles are behaving fine, then you can avoid ever having sounds play at the same time by letting the BG be sound manager.
I think hotmagic might be on the right track as long as the background is only affected by the mole touched attribute and never controls that attribute. Utopiangames made something work real nice in Bumps and I think he did a tutorial on how to do it but I don't remember you should prob try contacting him about it.