如何为我的spritekit游戏创建菜单屏幕?

时间:2014-12-31 20:33:19

标签: objective-c iphone menu sprite-kit

我已将我的实际Gamescene放入MyScene类中。即使我已经将游戏放入MyScene类,我怎样才能创建一个菜单屏幕。我试图在实际的gamecene之前包含菜单但是没有用

-(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;
}


-(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];
}
}

0 个答案:

没有答案