【问题标题】:How to make something like this?如何制作这样的东西?
【发布时间】:2014-05-03 18:40:46
【问题描述】:

我不确定我用“模态精灵套件场景”的措辞是否正确,但我想做的是在游戏完成时在场景上出现一个较小的场景。附上一张截图来说明我的意思:

截图来自 Flappy Bird,当玩家死亡时,游戏结束的小场景几乎像模态效果一样弹出,并显示用户的最终结果。我想知道如何去创建这个。

我试着在游戏结束后调用它:

[self.player runAction:death completion:^{
        [self removeAllActions];
        GameOverNode *gameOverNode = [[GameOverNode alloc] initWithScore:self.size];
        gameOverNode.gameScene = self;
        gameOverNode.position = CGPointMake(self.scene.size.width/2, -150);
        [self addChild:gameOverNode];
        [gameOverNode runAction:[SKAction moveToY:self.scene.size.height/2 duration:0.6]];

这是gameOverScene.m文件中gameOverNode的代码:

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

            self.userInteractionEnabled = YES;
            self.zPosition = 20;
            SKSpriteNode *bg = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(280*DoubleIfIpad, 300*DoubleIfIpad)];
            bg.alpha = 0.55;

但是节点只显示在屏幕的左下角,而不是像我想要的那样显示在中间。

我做错了什么?如何让小游戏结束节点弹出并坐在场景中间。

【问题讨论】:

  • 你能显示你的错误模式窗口的截图吗?如果您在左下角看到它,那么您的 SKAction moveToY 没有工作,或者您没有向我们展示整个代码。

标签: ios iphone objective-c sprite-kit


【解决方案1】:

你根本做不到。根据 Apple Docs 和多个 StackOverflow 帖子,您不能同时运行两个 SKScene。要重新创建您想要的效果,您可以创建一个具有与您想要的相似的边框和线条颜色的SKShapeNode,并在其中放置诸如乐谱之类的对象,或者您可以为弹出的屏幕创建一个图像并添加SKLabelNode s 到显示高分和当前分的场景。我附上了一张我如何为我的应用程序“Average Guy”创建最终“视图”的图片。

我使用这样的 SKShapeNode 制作了弹出屏幕:

SKShapeNode *optionsMenu = [SKShapeNode node];

CGRect    tempRect = CGRectMake(SELF_WIDTH/2, SELF_HEIGHT/2, SELF_WIDTH-20, (finalScoreLabel.position.y+(finalScoreLabel.frame.size.height/2)) - (mainMenuButton.position.y-(mainMenuButton.frame.size.height/2)) + 20);
CGPathRef tempPath = CGPathCreateWithRoundedRect(CGRectMake(tempRect.origin.x - tempRect.size.width/2, tempRect.origin.y - tempRect.size.height/2, tempRect.size.width, tempRect.size.height), 5, 5, Nil);

optionsMenu.path        = tempPath;
optionsMenu.fillColor   = [SKColor grayColor];
optionsMenu.strokeColor = [SKColor blueColor];
optionsMenu.zPosition   = 30;
optionsMenu.glowWidth   = 2.0f;

CGPathRelease(tempPath);

当然,不要介意繁琐的 CGRect 实现,我想让所有内容都适合所有屏幕尺寸,所以我没有对任何位置进行硬编码。至于添加分数和按钮,我是这样做的:

SKLabelNode *restartButton = [SKLabelNode labelNodeWithFontNamed:@"00 Starmap Truetype"];
restartButton.text         = @"Play Again";
restartButton.zPosition    = 31;
restartButton.fontColor    = [SKColor blueColor];
restartButton.fontSize     = 30;
restartButton.position     = CGPointMake(HALF_WIDTH, HALF_HEIGHT-50);
restartButton.name         = @"restart_button";

SKLabelNode *restartButtonShadow = restartButton.copy;
restartButtonShadow.position = CGPointMake(restartButton.position.x+1, restartButton.position.y-1);
restartButtonShadow.color = [SKColor colorWithRed:0 green:0 blue:.5 alpha:.1];

SKLabelNode *mainMenuButton = [SKLabelNode labelNodeWithFontNamed:@"00 Starmap Truetype"];
mainMenuButton.text         = @"Main Menu";
mainMenuButton.zPosition    = 31;
mainMenuButton.fontColor    = [SKColor blueColor];
mainMenuButton.fontSize     = 30;
mainMenuButton.position     = CGPointMake(HALF_WIDTH, HALF_HEIGHT - 85);
mainMenuButton.name         = @"main_menu_button";

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 2017-05-10
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多