0

touchesEnded でサウンドを再生しようとしていますが、問題が発生しています。移動するオブジェクトは複数あるため、オブジェクトを移動したときに次のコードが当てはまる場合、常にサウンドが再生されます。1回だけ再生するにはどうすればよいですか?

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    if(CGRectContainsRect([image1 frame], [image2 frame])){

        [self playsound];
    }
}
4

1 に答える 1

1

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

于 2010-04-30T03:40:52.057 に答える