如何让我的精灵套件场景出现在UIView上方?
我已经做了一些search,但没有find任何直接解决我的问题:我有一个SKScene
与几个SKNodes
每个SKSpriteNode
对象为我的游戏,我使用的背景UIImageView
(有一些事情,我需要做的背景至less在我看来,这不可能合理地用sprite工具包来完成)。 我遇到的问题是UIImageView
出现在一切之上,我看不到我的游戏对象。
在我的视图控制器(.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
(例如nodeHDU
, nodePlay
, nodePauseMenu
…),我使用UIImageView
作为背景(我在背景场景之间切换,使用一些不错的转换,如UIViewAnimationOptionTransitionCrossDissolve;
不能使用SKSpriteNode
作为背景来实现这一点,而不使用多个SKSpriteNodes
和一个复杂的SKActions
数组,所以我使用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
设置为控制器视图。 为了克服这个问题,不要让SKView
types的SKView
。 在故事板或Xib中执行以下步骤:
- 首先在控制器视图中添加一个
UIImageView
。 设置图像。 - 然后在
UIImageView
添加SKView
,并将UIClearColor
设置为背景颜色。
所以完整的层次结构就像UIViewController
– > UIView
– > UIImageView
– > SKView