Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MainMenuLayer.m
- // BalanceIt
- //
- // Created by SquirrelStudios on 16.05.10.
- // Copyright 2010 Squirrel Studios. All rights reserved.
- //
- #import "MainMenuLayer.h"
- #import "BalanceItAppDelegate.h"
- #import "SimpleAudioEngine.h"
- #import "TouchableSprite.h"
- @interface MainMenuLayer (Private)
- CCSprite *touchMeSprite_;
- CCSprite *logoSprite_;
- CCMenu *mnuMain_;
- - (void) goItemSelected:(id) sender;
- - (void) highScoreItemSelected:(id) sender;
- - (void) creditsItemSelected:(id) sender;
- - (void) fadeTouchMeItem:(CCNode *)node;
- @end
- @implementation MainMenuLayer
- + (CCScene *) scene {
- MainMenuLayer *layer = [MainMenuLayer node];
- CCScene *scene = [CCScene node];
- [scene addChild:layer];
- return scene;
- }
- -(id) init {
- if(!(self=[super init] ))
- return self;
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- self.isTouchEnabled = YES;
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- // background sprite
- CCSprite *bgSprite = [CCSprite spriteWithFile:@"bg_1.png"];
- bgSprite.position = ccp(0, 0);
- bgSprite.anchorPoint = ccp(0, 0);
- [self addChild:bgSprite];
- // background sprite end
- // touchme sprite
- if (app.splashed == NO) {
- touchMeSprite_ = [CCSprite spriteWithFile:@"touchme.png"];
- touchMeSprite_.position = ccp(winSize.width /2, 50);
- touchMeSprite_.opacity = 0;
- [self addChild:touchMeSprite_];
- [touchMeSprite_ runAction:[CCSequence actions:
- [CCDelayTime actionWithDuration:3],
- [CCFadeTo actionWithDuration:1 opacity:255],
- [CCCallFuncN actionWithTarget:self selector:@selector(fadeTouchMeItem:)],
- nil]];
- }
- else {
- touchMeSprite_ = nil;
- }
- // touchme sprite end
- // logo sprite
- logoSprite_ = [CCSprite spriteWithFile:@"logo.png"];
- if (app.splashed == NO)
- [logoSprite_ setPosition:ccp(winSize.width /2 , winSize.height /2 )];
- else
- [logoSprite_ setPosition:ccp(winSize.width /2 , winSize.height /2 + 70 )];
- [self addChild:logoSprite_];
- // logo sprite end
- // menu
- CCMenuItem *goItem = [CCMenuItemImage
- itemFromNormalImage:@"go.png"
- selectedImage:@"go.png"
- target:self
- selector:@selector(goItemSelected:)];
- goItem.position = ccp(0,0);
- CCMenuItem *highscoreItem = [CCMenuItemImage
- itemFromNormalImage:@"highscore.png"
- selectedImage:@"highscore.png"
- target:self selector:@selector(highScoreItemSelected:)];
- highscoreItem.position = ccp(-100,-90);
- CCMenuItem *creditsItem = [CCMenuItemImage
- itemFromNormalImage:@"credits.png"
- selectedImage:@"credits.png"
- target:self selector:@selector(creditsItemSelected:)];
- creditsItem.position = ccp(130,-85);
- mnuMain_ = [CCMenu menuWithItems:goItem, highscoreItem, creditsItem, nil];
- if (app.splashed == NO)
- mnuMain_.position = ccp(winSize.width /2 , -40);
- else
- mnuMain_.position = ccp(winSize.width /2 , 130);
- [self addChild:mnuMain_];
- // menu end
- NSLog(@"MainMenuLayer allocated");
- return self;
- }
- - (void) fadeTouchMeItem:(CCNode *)node
- {
- [node runAction:[CCRepeatForever actionWithAction:
- [CCSequence actions:
- [CCFadeTo actionWithDuration:0.5 opacity:100],
- [CCFadeTo actionWithDuration:0.5 opacity:255],
- nil]]];
- }
- - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- if (app.splashed == NO) {
- [logoSprite_ runAction:[CCMoveBy actionWithDuration:0.2 position:ccp(0, -5)]];
- [touchMeSprite_ stopAllActions];
- [touchMeSprite_ runAction:[CCFadeTo actionWithDuration:0.2 opacity:0]];
- }
- /*
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:[touch view]];
- location = [[CCDirector sharedDirector] convertToGL:location];
- */
- }
- - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- if (app.splashed == NO) {
- self.isTouchEnabled = NO;
- [logoSprite_ runAction:[CCMoveTo actionWithDuration:0.5 position:ccp(logoSprite_.position.x, logoSprite_.position.y + 70)]];
- [mnuMain_ runAction:[CCMoveTo actionWithDuration:0.5 position:ccp(mnuMain_.position.x, 130)]];
- app.splashed = YES;
- }
- }
- - (void) goItemSelected:(id) sender {
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- [app runCharacterSelectionScene];
- }
- - (void) creditsItemSelected:(id) sender {
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- [app runCreditsScene];
- }
- - (void) highScoreItemSelected:(id) sender {
- BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
- [app runCreditsScene];
- }
- - (void) dealloc {
- [super dealloc];
- NSLog(@"MainMenuLayer deallocated");
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement