Really weird issue going on here.
Using XCode6 with iOS8
I have a simple UIImageView, which moves across the screen when I click. No problem- works great.
I Just have a simple method to update specific labels...based on an int called StrikesLeft.
Here is my updateLabels method:
-(void)displayLabels{
//update strikes label
strikesLeftDisplay = [NSString stringWithFormat: @"%d", strikesLeft];
lblStrikes.text=strikesLeftDisplay;
}
Here is the weird issue though:
If I don't actually update the label, it runs no problem...but as soon as the label updates on the viewController, the UIImageView resets back to the starting position for some reason.
The UIImageView changing positions is in a NSTimer like so:
runningMovement=[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(startRunning) userInfo:nil repeats:YES];
*Edit- here is my startRunning Method:
- (void)startRunning{
if(livesLeft==0){[self endGame];}
manX=man.frame.origin.x;
manY=man.frame.origin.y;
if([direction isEqualToString:@"left"] && touchX < (manX+20)){
man.center=CGPointMake(man.center.x - runningSpeed,man.center.y);
}else if([direction isEqualToString:@"right"] && touchX > (manX+22)){
man.center=CGPointMake(man.center.x + runningSpeed,man.center.y);
}
else{
direction=@"0";
}
//animate runner
if ([direction isEqualToString:@"right"]){
if(runnerImageNumber==1){UIImage *image=[UIImage imageNamed:@"run1.png"];[man setImage:image];}
if(runnerImageNumber==2){UIImage *image=[UIImage imageNamed:@"run2.png"];[man setImage:image];}
if(runnerImageNumber==3){UIImage *image=[UIImage imageNamed:@"run3.png"];[man setImage:image];}
if(runnerImageNumber==4){UIImage *image=[UIImage imageNamed:@"run4.png"];[man setImage:image];}
if(runnerImageNumber==5){UIImage *image=[UIImage imageNamed:@"run5.png"];[man setImage:image];}
if(runnerImageNumber==6){UIImage *image=[UIImage imageNamed:@"run6.png"];[man setImage:image];}
if(runnerImageNumber==7){UIImage *image=[UIImage imageNamed:@"run7.png"];[man setImage:image];}
if(runnerImageNumber==8){UIImage *image=[UIImage imageNamed:@"run8.png"];[man setImage:image];}
if(runnerImageNumber==9){UIImage *image=[UIImage imageNamed:@"run9.png"];[man setImage:image];}
runnerImageNumber++;
if(runnerImageNumber==9){runnerImageNumber=1;}
}
if ([direction isEqualToString:@"left"]){
if(runnerImageNumber==1){UIImage *image=[UIImage imageNamed:@"run10.png"];[man setImage:image];}
if(runnerImageNumber==2){UIImage *image=[UIImage imageNamed:@"run11.png"];[man setImage:image];}
if(runnerImageNumber==3){UIImage *image=[UIImage imageNamed:@"run12.png"];[man setImage:image];}
if(runnerImageNumber==4){UIImage *image=[UIImage imageNamed:@"run13.png"];[man setImage:image];}
if(runnerImageNumber==5){UIImage *image=[UIImage imageNamed:@"run14.png"];[man setImage:image];}
if(runnerImageNumber==6){UIImage *image=[UIImage imageNamed:@"run15.png"];[man setImage:image];}
if(runnerImageNumber==7){UIImage *image=[UIImage imageNamed:@"run16.png"];[man setImage:image];}
if(runnerImageNumber==8){UIImage *image=[UIImage imageNamed:@"run17.png"];[man setImage:image];}
if(runnerImageNumber==9){UIImage *image=[UIImage imageNamed:@"run18.png"];[man setImage:image];}
runnerImageNumber++;
if(runnerImageNumber==9){runnerImageNumber=1;}
}
}