I have an iOS SpriteKit SKScene that contains a UIKit UITableView as part of the scene via View.AddSubview. Generally this works fine. I then create an SKNode that temporarily sits on top of the scene (to zoom in on a particular image) and I want it to be at the top of the z-order, so I set ZPosition of the new node to 999 arbitrarily. When the node is added, it appears on top of all the other SpriteKit nodes, but the UITableView is still at the top of the z-order and still accepts input even though there is a sprite node on top of it (supposedly).
Is there a way to set the z-order of a UIKit view when it is hosted on a SpriteKit scene so I can push it backwards?
Thanks for any suggestions.
This is not possible. Any UIView added to the SKView sits on top of everything rendered by the SKView. Nodes rendered by SKView and the SKScene itself aren't views, they are elements inside the SKView much like table cells are part of UITableView, but you can only change the draw order of the UITableView and the SKView. You can't take individual elements (nodes or cells) and draw them outside their container views.
The same issue exists in other 2d renderers by the way, be it cocos2d or plain OpenGL.
Related
So I am working on a simple SpriteKit ball and obstacle game. I have the zposition for the nodes set to 2 ( can be 1 but I set it to 2 to make sure it doesn’t interfere with anything else)
I am trying to add a background to it but instead of an image my I want to use a UIview as the background for my game. How should I use a uiview as a background for a SpriteKit scene. ?
The uiview I’m using is called Pastel. It’s a library that allows you to create animated gradient backgrounds like the Instagram app login screen.
I tried adjusting the position at
And I’ve even used the sendabove and sendbelow methods but they don’t work
In order for UIView with your background which is under SKView to become visible, you must set the allowsTransparency property of your SKView to true.
Edit:
you also need to set the SKView and the SKScene background color to clear – (thanks to Knight0fDragon)
Is it possible to add a UIView to a SceneKit SCNScene?
I have a need where I want a collectionview in the mid ground with some SCNNodes in front and behind.
I can get it working with a hack by screen-shotting the collectionview every-frame and then rendering this as a texture on a node, but it's very slow.
Any other ways around it?
No the is no standard way to bring a uiview in mid of scnnodes.
Try to stack a skscene to diffuse contents in your scnnode.
After that bring a uiview to the skscene.
I have a SKScene in which i have bunch of sprites and physic stuff. I needed to add UIView to SKView who presented the scene. Now i need to put some SKNode over UIView. But when I add child to my scene, UIView is displayed at top, and newly added nodes stays below. Is it possible to show newly added nodes over UIView components ?
The short answer is no.
You already have a UIView which you can access in the view from didMoveToView:(SKView *)view. All nodes reside in that view. If you add another view, it either goes in front or behind the 'SKView'.
I am building a spritekit game with 2 screens. Inside the 1st screen the player should pick one Hangar out of 6-7, by horizontal scrolling. When one picked a new SKScene will appear with the actual game play. For scrolling - One Hangar should be centered, while two others are partly shown from the sides.
Can it be done with UIScrollView, on top of SKScene? Or better use sprite nodes for it?
I am just not sure about the best way to handle user interface with sprite kit.
I would implement this by putting the hangars as children of a SKNode. Swiping would move this this SKNode move around with all it's children.
If you wanted the positioning you described; when the swiping has stopped I would use an SKAction to center a the hangar closest to the middle of the screen.
I would do it like this because I think you should only mix in UIKit when necessary because :
It is easier to port to OSX
You don't have to convert between different types of coordinate systems
I have a UIScrollView added onto as a subview from within the SKScene. The code is running perfectly but I am unable to fix its Z position relative to some of the SKSpriteNode existing on the main SKScene view. Is there any way this can be done. By adding the UIScrollView as a subview, its completely over the top of any other SKSpriteNodes on my scene.
Please help me out!
This can't be done. All elements inside a SKView are, well, part of the SKView. Any other view can only be in front of or behind the SKView.