如何让我的精灵工具包场景出现在UIView上方? [英] How to make my sprite kit scene appear above a UIView?
问题描述
我已经做了一些搜索,但没有发现任何直接解决我的问题:我有一个 SKScene
,有几个 SKNodes
每个 SKSpriteNode
我的游戏对象,我使用的是背景 UIImageView
(有些东西我需要使用精灵套件无法合理完成的背景 - 至少据我所知);我遇到的问题是 UIImageView
出现在所有内容之上,我看不到我的游戏对象。
I've done some searching but haven't found anything directly addressing my issue: I have an SKScene
with several SKNodes
each with SKSpriteNode
objects for my game, and I am using a background UIImageView
(there are some things I need to do with background that cannot be reasonable done with sprite kit - to my knowledge at least); the problem I'm having is that the UIImageView
appears above everything and I can't see my game objects.
在我的视图控制器(.m文件)中,我有以下代码来调用我的场景
In my view controller (.m file) I have the following code to call my scene
@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
作为背景,不使用多个 SKSpriteNodes
和一个复杂的 SKActions
数组,所以我m使用 UIImageView
)
In the GameScene
above, I have several SKNodes
where all my game objects are children of (for example nodeHDU
, nodePlay
, nodePauseMenu
...), and I am using a UIImageView
as my background (I am switching between background scenes over time and am using some nice transitions such as UIViewAnimationOptionTransitionCrossDissolve;
couldn't accomplish this with a SKSpriteNode
as background without using multiple SKSpriteNodes
and an intricate array of SKActions
so I"m using 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没有帮助。
However, the ImageBackground
above is the only thing I see when running the app in Xcode. The other objects from my game (children of other nodes) exist, and various NSLog
statements are getting called, but they seem to appear behind the ImageBackground
I have. The code above "belowSubview" and "sendSubviewToBack" don't help.
那么如何发送 imageBackground
实际上是背景?
So How can I send the imageBackground
to actually be the background?
推荐答案
你的问题在于你直接设置 SKView
作为控制器视图。要解决此问题,请不要使 self.view
一种 SKView
。在故事板或Xib中执行以下步骤:
Your problem is here that you are directly setting SKView
as a controller view. To overcome from this issue don't make self.view
a type of SKView
. Do the following step in your storyboard or Xib :
- 添加
UIImageView
控制器的视图首先。同时设置图像。 - 然后在
UIImageView
上添加SKView
并将UIClearColor
设置为背景颜色。
- Add an
UIImageView
on the controller's view first. Set the image as well. - Then add a
SKView
over theUIImageView
and setUIClearColor
to the background colour.
所以完整的层次结构就像 UIViewController
- > UIView
- > UIImageView
- > SKView
So the complete hierarchy is like UIViewController
->UIView
->UIImageView
->SKView
这篇关于如何让我的精灵工具包场景出现在UIView上方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!