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.
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];
}
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;
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.
So How can I send the imageBackground
to actually be the background?
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
on the controller's view first. Set the image as well.SKView
over the UIImageView
and set UIClearColor
to the background colour. So the complete hierarchy is like UIViewController
->UIView
->UIImageView
->SKView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With