Scenekit orientation in IOS - ios

I have imported a Collada file into my scene and I am using allowsCameraControl to rotate / pan the object / pan the object
I now need functionality to jump instantly to the front or side view of the object.
Does anybody know how I can get the camera that Scenekit implements in my scene and how to rotate this camera to show the front and back view ?

"Front view" and "side view" are notions that are defined in terms of your content, so you have to define them yourself.
Create a node (let's call it "frontViewNode" for example) with an attached SCNCamera and position/orient it so that it's looking at whatever you call the "front" of your object. See this answer if you need help with that.
Create another node ("sideViewNode") that's looking at whatever you call the "side" of your object.
When you want to switch views, set the pointOfView property on the SCNView displaying your scene to either your "frontViewNode" or your "sideViewNode". You can even do this inside an animation (see SCNTransaction) to make the camera view swoop around between the two viewpoints.

Related

How to make two screens show simultaneously like in snapchat?

I am creating a camera roll feature similar to snapchat where the camera is the bottom layer and then after tapping a button the camera roll appears. The camera roll does not occupy the whole screen the search bar on the top is still maintained and upon dismissal with a swipe gesture down the camera is still running. I am not sure how this affect is achieved. Is it done by using a scroll view or a segue of some kind? Thank you for your help.
Below is the video in question
Snap Chat Camera Roll
Firstly, this type of effect cannot be achieved using the standard camera UIImagePickerController. You will need to create your own camera view.
Here is a good guide to get you started: https://github.com/codepath/ios_guides/wiki/Creating-a-Custom-Camera-View
You could also try using a custom library that can be easily customized such as: https://github.com/omergul/LLSimpleCamera/
Now, in terms of the actual visual, I do not believe there is any actual segue/change of viewcontroller involved. The camera view is probably always on screen (except perhaps when it is fully covered by the Memories screen), it is simply overlayed by other things.
The Memories screen is most likely 'presented' in a custom manner. The show/dismissal logic can be achieved by attaching a UIPanGestureRecognizer to the UIView and translating the view up and down on pan event. If the pan's y value passes a certain threshold up or down, it automatically continues its animation to show or hide the view.

rotating a coordinate cross in SCNScene to mirror camera movements

I am new to SceneKit and I could use your help with the following:
I have two SCNViews
- a large one (skView) showing the scene for the user which can be manipulated by the user with the standard allowsCameraControl option enabled
- another small one (coordinateCrossView) in the left corner which shows a coordinate cross that I would like to mirror any camera navigation the user performs in the large SCNView
I implemented it by making the ViewController which holds both SCNViews a SCNRendererDelegate and by updating the cross' orientation in the renderer: updateAtTime: method like so:
- (void)renderer:(id<SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time {
[self.coordinateCrossView.scene.rootNode childNodeWithName:#"cross" recursively:YES].orientation = self.skView.pointOfView.orientation;
[self.coordinateCrossView setNeedsDisplay];
}
So far so good. However, this only works when the user is manipulating the large SCNView with a finger on the screen. After as swipe gesture when the finger leaves the screen the object in the large SCNView continues to rotate a bit - but the coordinate cross is not updated.
Any ideas why this behavior is not captured by the pointOfView.orientation changes?
I found out what the problem was: the small coordinateCrossView was not continuously updated and therefore even though the coordinate cross' orientation was changed, the view didn't show it - even though setNeedsDisplay was called.
I fixed the issue by setting the isPlaying property of the coordinateCrossView which forces it to be updated.

using SKScene or SKShapeNode for a game world

I'm following this question's advice on how to create my game world for a scroller game with camera centered on the player. However, the advice says to use an SKShapeNode; I don't know how I feel about that.
Are there any advantages/disadvantages to using either a shape node or an skscene (or another type of object/node)? Is there a node that is considered best practice to use as a world?
Also, is it possible to create an skscene inside an skscene, or is that bad practice/discouraged?
Thank you!
You can't put a scene inside a scene per-say but you could stagger view controllers and place a view controller on top of another and then put the scene on top of that inset view controller.
The way I implement my scroller games is to put the player in the center and then move the background around. (Checking for bounds of course.)
As far as your advantages/disadvantages I'm not sure what you mean by the SKNodes; that's how you should do it if you're working just in SpriteKit. But don't add another SKScene unless you have something that you can't implement in just one SKScene.

How to share Background SpriteNode among Multiple Scenes?

Well, the title says it all. If I am currently in a presented Scene of which I have initialized a Background SpriteNode to be a class constant, then how do I use the same Background SpriteNode in my next presented scene without having to create another SpriteNode that behaves and looks exactly the same as in the previous scene.
Will creating another SpriteNode be costly, assuming the background object loads its texture from a texture atlas?
And, I am using Swift.
Something like this should work.
backgroundSprite.removeFromParent()
nextScene.addChild(backgroundSprite)

Overlay scenes/regions

I am working on my first spritekit app and had a quick question on how to handle something I had in mind. I am working on a prototype of a board game I had in mind and wanted to do some brainstorming in an iOS Map.
The main scene is a world map that the user can pan around. I have this working at the moment. My next step is to create some overlay that would appear with a bunch of actions/cards available for the user to activate.
Do you guys have any tips on how to set this up? Would this overlay be another scene? I don't think that is correct since the SKView can only present 1 scene at a time. In addition, I currently have a UIPanGestureRecognizer, I would want this to stop working in the region my overlay is in.
Any help is appreciated!
You can create an SKNode and add your actions/cards to that node. You can then add the node to your world map node (so it pans appropriately) as an overlay. You should set the zPosition of the overlay node to a value larger than your world map's zPosition so it appears over the map.

Resources