【问题标题】:Making a SKScene's background transparent not working... is this a bug?使 SKScene 的背景透明不起作用......这是一个错误吗?
【发布时间】:2013-09-24 12:38:42
【问题描述】:

有没有一种方法可以使 SKScene 的背景透明,并通过透明度将那个场景呈现在另一个场景之上。

我们的想法是让所呈现场景的背景如下:

self.backgroundColor = [SKColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];

什么可以让看到背后的场景变暗。但这样做是行不通的。背景呈现完全不透明。

有没有办法做到这一点?

【问题讨论】:

    标签: iphone ios ipad sprite-kit


    【解决方案1】:

    在 iOS 8 中,您可以将场景的 SKView 设置为允许透明,并将场景的背景颜色设置为具有透明性。然后会看到 SKView 后面的视图。

    UIView *parentView = ...;
    [parentView addSubview:backgroundView];
    [parentView addSubview:skViewWithScene];
    skViewWithScene.allowsTransparency = YES;
    scene.backgroundColor = [UIColor clearColor];
    [skViewWithScene presentScene:scene];
    

    【讨论】:

    • 之前发布的答案仍然正确——SpriteKit 视图在 iOS 7 和 OS X v10.9 (Mavericks) 中不支持透明度。透明 SKViews 需要 iOS 8 或 OS X v10.10 (Yosemite)。
    【解决方案2】:

    透明度仅适用于 iOS 8,必须检查 iOS 7

    在 ViewController 中设置透明度为:

    SKView *skView = (SKView *)self.mySKView;
    SKScene *skScene = [MyScene sceneWithSize:skView.bounds.size];
    skScene.scaleMode = SKSceneScaleModeAspectFill;
    skView.allowsTransparency = YES;
    [skView presentScene: skScene];
    

    在 MyScene.m 中将背景设置为透明色:

    self.scene.backgroundColor = [UIColor clearColor];

    【讨论】:

      【解决方案3】:

      斯威夫特 3

      @IBOutlet var gameScene: SKView!
      
      func setupGameScene(){
      
          if let scene = SKScene(fileNamed: "GameScene") {
              scene.scaleMode = .aspectFill
              scene.backgroundColor = .clear
              gameScene.presentScene(scene)
              gameScene.allowsTransparency = true
              gameScene.ignoresSiblingOrder = true
              gameScene.showsFPS = true
              gameScene.showsNodeCount = true
          }
      }
      

      【讨论】:

        【解决方案4】:

        你不能让场景透明。如果有什么你想让视图透明的。

        但是,您不能同时运行两个场景(仅在它们之间转换),虽然您可以将多个 SKView 添加到 Storyboards 页面,但只有一个视图会全速更新,其他视图会冻结或更改仅每隔几秒播放一次。

        【讨论】:

          【解决方案5】:

          我认为这是不可能的,因为据我所知,我尝试了所有方法,它一直忽略 alpha 值。

          这是不合逻辑的,因为它在 OpenGL 之上工作,但 SKView 是 UIView 的子类,而不是 GLKView 的子类。

          【讨论】:

          • SpriteKit 在这一点上几乎完成了一半。我必须创建很多控件以使其工作最少。带有一行文本的 SKLbeNodes?真的吗? SKShapeNodes 不适用于遮罩和其他东西。
          猜你喜欢
          • 1970-01-01
          • 2016-06-14
          • 2021-10-13
          • 1970-01-01
          • 1970-01-01
          • 2015-04-25
          • 1970-01-01
          • 2011-07-28
          • 2016-10-23
          相关资源
          最近更新 更多