Tutorial :touchesEnded Sound?


I'm trying to play a sound on touchesEnded but I'm having a problem. There are multiple objects that get moved around, so if the below code holds true when any object is moved, it constantly plays the sound. How do I only play it once?

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{        if(CGRectContainsRect([image1 frame], [image2 frame])){            [self playsound];      }  }  


If you only want it to play for a certain object that calls touchesEnded, you first need to identify that object and then you can just do a quick if-then statement.

If you only want it to play once, then just give it a quick variable like int playCount = 0; and then set it to playCount = 1; after you're done playing and do an if-then statement on that as well (i.e. play it if playCount is 0, don't play it if playCount is 1).

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »