Hello,
I am having trouble with my game and was wondering if anyone can help?
I am loading an overlay image on the screen when a user clicks on an answer in my quiz game, the image is of either a tick or cross to indicate if the answer was correct. The image is being loaded in a new thread.
The problem is that the image does not appear every-time the user clicks on an answer, it only appears about 20% of the time in one round.
Whats even more weird though is that i had the game a few months ago ready on iOS3 and this problem didn't occur, it only seemed to start when updating to iOS4.
Here is the code:
The images are created in the loadView method:
tick = [UIImageView alloc];
[tick initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[tick setImage:[UIImage imageNamed:@"correct.png"]];
cross = [UIImageView alloc];
[cross initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[cross setImage:[UIImage imageNamed:@"wrong.png"]];
The threads are called here:
-(void)answerAttempt:(UIButton *)b{
ansQues++;
if([b.currentTitle isEqualToString:ans]){
[NSThread detachNewThreadSelector: @selector(showTick) toTarget:self withObject:nil];
[appDelegate playSound:1];
score++;
...
...
...
}else{
[NSThread detachNewThreadSelector: @selector(showCross) toTarget:self withObject:nil];
[appDelegate playSound:0];
}
Here is the function the two threads call:
-(void)showTick{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[tick setHidden:NO];
[levelPage addSubview:tick];
[levelPage bringSubviewToFront: tick];
usleep(500000);
[tick removeFromSuperview];
[pool release];
}
-(void)showCross{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[cross setHidden:NO];
[levelPage addSubview:cross];
[levelPage bringSubviewToFront: cross];
usleep(500000);
[cross removeFromSuperview];
[pool release];
}
As you might be able to tell from the code, ive tried various ways to try and get it to display everytime, but have not found any solution for some time now. I have checked to make sure that the correct thread is being called each time, and it does - just UIImage for tick and cross does not display.
Please feel free to ask any further questions.
Thanks.