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.
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)
Im making a scene for my game. Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. (Im using a normal Viewcontroller).
In the game you are supposed to move an image to another image without colliding with obstacles. The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win.
But when my image moves, the view doesnt follow with my image. How do you do that?
I would be so thankful for any answear! Thanks.
I am assuming you are using SpriteKit yeah? The UIView size is not related to the scene size. So changing those will not make your scene any different.
To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
Scroll down to Example: Centering the Scene on a Node
Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around.
If you are targetting only iOS9 and above, you can use SKCameraNode and set:
SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = #"camNode";
self.camera = cameraNode;
Then you add your "character" (that is to be moved together with the camera) into the cameraNode. Then any movement, you need to move the cameraNode instead of the "character".
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.
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.