mercredi 31 décembre 2014

how can I create a menu screen for my spritekit game?

I already put my actual Gamescene inside the MyScene class. How can I create a menu screen even If I already put the game in the MyScene class. I tried to include the menu before the actual gamescene but that didnt work


enter code here-(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) {



if (self = [super initWithSize:size]){
SKSpriteNode *startButton = [SKSpriteNode spriteNodeWithImageNamed:@"startButton"];
startButton.position = CGPointMake(160, 300);
startButton.size = CGSizeMake(200, 200);
startButton.name = @"startButton";
[self addChild:startButton];
}
return self;
/* Setup your scene here */
self.anchorPoint = CGPointMake(0.5, 0.5);
self.physicsWorld.contactDelegate = self;
//SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithImageNamed:@""];
//[self addChild:bgImage];
self.backgroundColor = [SKColor colorWithRed:0.171875 green:0.2421875 blue:0.3125 alpha:1.0];


world = [SKNode node];
[self addChild:world];

self.physicsWorld.contactDelegate = self;

generator = [SPWorldGenerator generatorWithWorld:world];
[self addChild:generator];
[generator populate];


hero = [SPHero hero];
[world addChild:hero];

[self loadScoreLabels];

cloud1 = [SPHero cloud1];
[world addChild:cloud1];

cloud2 = [SPHero cloud2];
[world addChild:cloud2];

cloud3 = [SPHero cloud3];
[world addChild:cloud3];

cloud4 = [SPHero cloud4];
[world addChild:cloud4];
//uihui//

SKLabelNode *tapToBeginLabel = [SKLabelNode labelNodeWithFontNamed:GAME_FONT];
tapToBeginLabel.name = @"tapToBeginLabel";
tapToBeginLabel.text = @"tap to begin";
tapToBeginLabel.fontSize = 20.0;
[self addChild:tapToBeginLabel];
[self animateWithPulse:tapToBeginLabel]; // ** GETS RESET LABEL PULSING ** //

// ** PULSING TEXT ** //
SKAction *disappear = [SKAction fadeAlphaTo:0.0 duration:0.6];
SKAction *appear = [SKAction fadeAlphaTo:1.0 duration:0.6];
SKAction *pulse = [SKAction sequence:@[disappear, appear]];
[tapToBeginLabel runAction:[SKAction repeatActionForever:pulse]];
// ** PULSING TEXT ** //


}

return self;


}


enter code here-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInNode:self];



SKNode *node = [self nodeAtPoint:location];

if ([node.name isEqualToString:@"startButton"]) {

SKTransition *transition = [SKTransition doorsOpenVerticalWithDuration:1.0];

MyScene *game = [[MyScene alloc] initWithSize: CGSizeMake(self.size.width, self.size.height)];

[self.scene.view presentScene:game transition:transition];
}


}




Aucun commentaire:

Enregistrer un commentaire