Hello all, i am making a simple game where i need a button to activate a timer the counts down from 30 seconds, and then when it gets to 0 seconds, load another view. I have searched all day and found only bits and pieces of code that partially work, but nothing solid. Any code or sample projects would be appreciated.
I dont think you've looked very hard then. I'll assume you know how to work with interface builder, and you know some very basic programming stuff.
Code:
-(IBAction)onButtonPress
{
theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector( updateTimerDisplay) userInfo:nil repeats:YES];
}
-(void)updateTimerDisplay
{
//set label text or whatever to current time left
//decrement current time left
if( timeLeft <=0 ) // a class var you can setup yourself. Hope you can do this
{
[theTimer invalidate]; //this stops the timer
//now you can load the next view
// ...
}
}
I dont think you've looked very hard then. I'll assume you know how to work with interface builder, and you know some very basic programming stuff.
Code:
-(IBAction)onButtonPress
{
theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector( updateTimerDisplay) userInfo:nil repeats:YES];
}
-(void)updateTimerDisplay
{
//set label text or whatever to current time left
//decrement current time left
if( timeLeft <=0 ) // a class var you can setup yourself. Hope you can do this
{
[theTimer invalidate]; //this stops the timer
//now you can load the next view
// ...
}
}
I actually just figured it out before you told me.
My only question now, is how do i load another view when the timer reaches 0?