Hi, so I have a game that I am trying to add a main menu too. But I can't get the main menu to show up...attached is a screenshot of what my storyboard looks like.
However when I click run instead of showing the main menu, it just proceeds to the game.
Any help is appreciated...also I didn't know what parts of my code I would need to post so if you need to see code to help just ask and I'll post it.
TIA
This is the code for my ViewController.m
However when I click run instead of showing the main menu, it just proceeds to the game.
Any help is appreciated...also I didn't know what parts of my code I would need to post so if you need to see code to help just ask and I'll post it.
TIA
This is the code for my ViewController.m
Code:
//
// ViewController.m
// Tap Me
//
// Created by Ryan on 4/27/13.
//
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (AVAudioPlayer *)setupAudioPlayerWithFile:(NSString *)file type:(NSString *)type
{
// 1
NSString *path = [[NSBundle mainBundle] pathForResource:file ofType:type];
NSURL *url = [NSURL fileURLWithPath:path];
// 2
NSError *error;
// 3
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
// 4
if (!audioPlayer) {
NSLog(@"%@",[error description]);
}
// 5
return audioPlayer;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_tile.png" ]];
scoreLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"field_score.png"]];
timerLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"field_time.png"]];
buttonBeep = [self setupAudioPlayerWithFile:@"ButtonTap" type:@"wav"];
secondBeep = [self setupAudioPlayerWithFile:@"SecondBeep" type:@"wav"];
backgroundMusic = [self setupAudioPlayerWithFile:@"HallOfTheMountainKing" type:@"mp3"];
UIAlertView *alerted = [[UIAlertView alloc] initWithTitle:@"Get Ready" message:[NSString stringWithFormat:@"Press Start!"] delegate:self cancelButtonTitle:@"Start" otherButtonTitles:nil];
[alerted show];
}
- (void)awakeFromNib {
setHigh = [[NSUserDefaults standardUserDefaults] integerForKey:@"highScore"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPressed {
count++;
scoreLabel.text = [NSString stringWithFormat:@"Score:\n%i", count];
[buttonBeep play];
}
- (void)subtractTime {
// 1
seconds--;
timerLabel.text = [NSString stringWithFormat:@"Time: %i",seconds];
[secondBeep play];
// 2
if (seconds == 0) {
if (count < highScore) {
[timer invalidate];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Time is up!" message:[NSString stringWithFormat:@"You scored %i points!", count] delegate:self cancelButtonTitle:@"Play Again" otherButtonTitles:nil];
[alert show];
}
else if (count > highScore) {
[timer invalidate];
(setHigh = count);
UIAlertView *display = [[UIAlertView alloc] initWithTitle:@"High Score!" message:[NSString stringWithFormat:@"You got a new high score of %i!", count] delegate:self cancelButtonTitle:@"Play Again" otherButtonTitles:nil];
[display show];
[[NSUserDefaults standardUserDefaults]setInteger:setHigh forKey:@"highScore"];
}
}
}
- (void)setupGame {
// 1
seconds = 30;
count = 0;
highScore = setHigh;
// 2
timerLabel.text = [NSString stringWithFormat:@"Time: %i", seconds];
scoreLabel.text = [NSString stringWithFormat:@"Score:\n%i", count];
highLabel.text = [NSString stringWithFormat:@"High Score:\n%i", highScore];
// 3
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(subtractTime)
userInfo:nil
repeats:YES];
[backgroundMusic setVolume:0.3];
[backgroundMusic play];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[self setupGame];
}
- (IBAction)restartPressed{
[timer invalidate];
[self viewDidLoad];
}
- (int)getBannerHeight:(UIDeviceOrientation)orientation {
if (UIInterfaceOrientationIsLandscape(orientation)) {
return 32;
} else {
return 50;
}
}
- (int)getBannerHeight {
return [self getBannerHeight:[UIDevice currentDevice].orientation];
}
@end
Attachments
Last edited: