【问题标题】:Game Over Screen - SpriteKit游戏结束屏幕 - SpriteKit
【发布时间】:2014-03-01 19:50:50
【问题描述】:

我正在构建一个简单的 SpriteKit 游戏。我想添加一个游戏结束屏幕,带有一个返回主屏幕的按钮。但似乎用 SpriteKit 做起来并不容易。

我之前在主游戏视图上有一个“返回”按钮,当 Game Over 视图加载时该按钮停留在那里。 Bur使用它并再次播放会使fps下降。那么,有没有办法向SKScene 添加按钮?例如像在 Storyboard 中创建一个 View Controller 并在那里添加按钮,然后让 Scene 出现在那里......

如果您需要任何代码或任何东西,请告诉我,我会发布它。谢谢!

【问题讨论】:

  • 将 UIButton 作为子视图添加到 SKView 不是一种选择,对吧?那么FPS会下降吗?
  • 好吧,至少从故事板来看,它发生了。我认为 ARC 只是保留了内容,但我不知道如何发布它们......

标签: ios iphone sprite-kit


【解决方案1】:

最好的方法是继承SKNodeSpriteKit 中创建一个按钮。

简单示例:

@interface MyButton : SKSpriteNode

@property (nonatomic, readonly) SEL action;
@property (nonatomic, readonly, weak) id target;

- (void)setTarget:(id)target action:(SEL)action;

@end

@implementation SKButton

- (void)setTarget:(id)target action:(SEL)action 
{
    _target = target;
    _action = action;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInNode:self.parent];

    if (CGRectContainsPoint(self.frame, touchPoint)) 
    {
        objc_msgSend(_target, _action);
    }
}

@end

或者您可以创建一个UIButton 并将其添加到SKView

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
button.backgroundColor = [UIColor whiteColor];

[skView addSubview:button];

我没有遇到任何性能问题,但我的测试项目并不复杂。

【讨论】:

  • 谢谢,我会把它留给未来的项目/想法! :D
【解决方案2】:

嗯,我找到了一个适合我的简单解决方案(至少现在是这样)。这里是:http://meghagulati.com/2014/01/20/simple-parse-tutorial-with-sprite-kit-game/

作者创建了一个节点,然后当节点被触摸时,游戏再次加载。代码可以在它的网站上看到。

【讨论】:

  • 他或她正在使用 SKLabel。
猜你喜欢
  • 2013-12-24
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 2014-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多