views:

37

answers:

1

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];
    }
}
A: 

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 NSInt 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).

iWasRobbed