Possible Duplicate:
Generating Random Numbers in Objective-C
Hi I am creating an app where when you press a pimple it travels to a random place in the view. THe pimple is a UIImageView. Here is the code that I put in:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:pimple];
if ( CGRectContainsPoint(pimple.bounds, point) ) {
[self checkcollision];
}
}
-(void)checkcollision
{
pimple.center = CGPointMake(random(), random());
sad.hidden = NO;
NSURL* popURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pop" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((CFURLRef) popURL, &popID);
AudioServicesPlaySystemSound(popID);
}
This code: pimple.center = CGPointMake(random(), random()); does not work. When I press the pimple, the pimple dissapears. Since I have not stated any .hidden for the pimple it must mean it IS moving. But you cant see it, (its outside the view.) Is there something wrong with my code? Am i missing something? Please help.