我做了一些搜索,但没有找到任何直接解决我的问题的东西:我有一个 SKScene
有几个 SKNodes
每个都有 SKSpriteNode
我的游戏的对象,并且我正在使用背景 UIImageView
(有一些我需要用背景做的事情不能用 sprite kit 合理地完成 - 至少据我所知);我遇到的问题是 UIImageView
出现在所有内容之上,我看不到我的游戏对象。
在我的 View Controller (.m 文件)中,我有以下代码来调用我的场景
@implementation GameViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SKView * skView = (SKView *)self.view;
SKScene * scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];
}
在上面的 GameScene
中,我有几个 SKNodes
,我所有的游戏对象都是它们的子对象(例如 nodeHDU
、nodePlay
, nodePauseMenu
...), 我正在使用 UIImageView
作为我的背景因为 UIViewAnimationOptionTransitionCrossDissolve;
在不使用多个 SKSpriteNode
和复杂的 SKActions
数组的情况下无法使用 SKSpriteNode
作为背景来完成此操作> 所以我正在使用 UIImageView
)
UIView *backgrounds = [[UIView alloc] init];
[self.view insertSubview:backgrounds belowSubview:self.view];
UIImageView *imageBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
[backgrounds addSubview:imageBackground];
[backgrounds sendSubviewToBack:imageBackground];
[imageBackground setImage:[UIImage imageNamed:@"1-A.png"]];
imageBackground.alpha=1.0;
但是,上面的 ImageBackground
是我在 Xcode 中运行应用程序时看到的唯一内容。我游戏中的其他对象(其他节点的子节点)存在,并且调用了各种 NSLog
语句,但它们似乎出现在我拥有的 ImageBackground
后面。 “belowSubview”和“sendSubviewToBack”上面的代码没有帮助。
那么我怎样才能发送 imageBackground
作为背景呢?
最佳答案
您的问题在于您直接将 SKView
设置为 Controller View 。要解决此问题,请不要将 self.view
设为 SKView
的类型。在 Storyboard或 Xib 中执行以下步骤:
- 首先在 Controller 的 View 上添加一个
UIImageView
。也设置图像。 - 然后在
UIImageView
上添加一个SKView
并将UIClearColor
设置为背景色。
所以完整的层次结构就像UIViewController
->UIView
->UIImageView
->SKView
关于ios - 如何让我的 sprite kit 场景出现在 UIView 之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30250701/