Can I render the same SKScene to two different views simultaneously? - swift

I want to render two SpriteKit SKViews at the same time which share a common SKScene. I'd like each SKView to show a different part of the scene (e.g. from a different SKCameraNode). Is this possible?
What I've tried: I've instantiated two SKViews and called .presentScene(mySharedScene) on both of them. I can render those views simultaneously and animations work just fine. But since the camera position is set on the SKScene itself via the .camera property, I can't assign a different camera to each SKView.
Ultimately, I'd like to create a simple bouncing ball that leverages SpriteKit's physics engine. Each SKView will be displayed on a different physical monitor, and the ball should be able to bounce between them. I'm doing this purely as a learning exercise.

Yes, you can, I have done split screens before, but let me tell you. It is a real pain. All of your updates get called twice, so you are going to have to develop a system that works around it. Instead, for a simple experience I recommend copying your scene to your 2nd View then updating your camera to your new location.
func didFinishUpdate()
{
let copy = scene.copy()!
view2.presentScene(copy)
copy2.camera!.position = newPosition
}

Related

Renderer.OnBecameVisible for scenekit?

In Unity, there is an event (Rendered.OnBecameVisible) that you can subscribe to to know when an object (in SceneKit's parlance, an SCNNode) becomes visible "by any camera".
Does Scenekit have an equivalent method/functionality/event subscription/or anything remotely similar I can use to achieve the same-ish functionality? (calling a method when an SCNNode is "visible" by a camera)
https://docs.unity3d.com/ScriptReference/Renderer.OnBecameVisible.html
There is no delegate method you could implement, but your SCNSceneRenderer, typically your SCNView, has a isNode(_:insideFrustumOf:) method:
Use this method to test whether a node lies within the viewing frustum defined by another node (which may or may not be the scene renderer’s current pointOfView node). For example, in a game scene containing multiple camera nodes, you could use this method to determine which camera is currently best for viewing a moving player character.

Switch between scenes but keep player position when comes back?

My game will switch between two scenes : scene A and scene B;
scene A is a world where the hero can walk around and trigger battles;
scene B is the battle scene;
when the battle finished, I want to turn back to scene A and hero should be in the position where it trigger battles. So I need to save scene A before I load scene B;
I tried the api LoadSceneMode.Additive; But it's just used to mix one scene to the current loaded scenes.
Could you help me plz?
Firstly DO NOT use "additive". Just use ordinary scene load.
Secondly you have the problem of "remembering" where the guy was when sceneA loads.
Your easiest approach to get you going .. learn about PlayerPrefs.
Just before you quite sceneA, save the hero's position. When you load sceneA, get the hero's position.
Alternately you can use one static class as a sort of global to keep track of the info. But to do that you have to learn about writing that sort of code.
Be aware that what you're doing is not that easy - Unity is a lot harder than it says on the box.
I encourage you to master PlayerPrefs in the first instance, because you will have to use it all the time anyway.

How to show 2 scenes on screen at the same time

How can I show 2 scenes on the screen at the same time on Sprite Kit Swift?
I need to first scene be placed of the second (I need one scene to be seen and atop of it appeared other scene, which has some sprites).
Or tell me, how developers make, for example, menu (with buttons like "restart", "results") to appear on other scene when player dies? And that time, also you can see the main scene with location (or with dead character)?
You do not need 2 scenes. However, you can accomplish what you are after with basing an node tree off of an SKNode. For your menu idea you could build it out of however many objects you'd like, but since it is based from an SKNode, you can animate it to your hearts content. No need for two scene, just build another node tree and animate the root. If that isn't enough answer, I could write some code to help you out if need be. Sorry watching the Netflix and feeling lazy.

can't interact (in game view) with objects displayed by secondary camera - Unity

I have two cameras that occupy different spaces in the Game view. The problem is that I can interact with my object shown by the main camera, but when I move this object (in scene view) to make it appear in the visual field of the second camera, the object is displayed in Game view but I can't interact with it (the object is a scroll Rect btw) through Game view. Seems to have a very simple solution but I couldn't find it.
Here are the parameters of both cameras:
Main Camera:
Pretty sure you can only interact with the current MainCamera in Unity.
If you could explain what you're trying to achieve with 2 cameras maybe we can help you find a better solution.

How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?

I am developing an iPad game that uses cocos2d and requires a virtual joystick. I have a prototype up and running using SneakyJoystick.
However, I realized that my game design requires me to use CCTransitions to move the user between different instances of CCScene in order to get the visual effect I want. The problem is, I don't want the user controls (like the joystick) to be affected by the CCTransitions- I want them to remain on the screen (in a different part of the screen than the part occupied by the CCScene.)
I realized the only way to do this was to keep the entire cocos2d environment in an EAGLView that occupies an area smaller than the entire screen, which allows me to keep all the user controls elsewhere on the screen, where they are unaffected by the scene transitions.
The problem is, that means SneakyJoystick is probably no longer an option, as it is a CCNode that therefore will probably only run within the cocos2d scene graph.
I am curious if anyone has an alternative solution for this situation: A way of implementing a virtual joystick outside the cocos2d environment, but that can somehow communicate fluidly with the cocos2d scene.
It would be great if I could retain the functionality of SneakyJoystick or something very similar, by either tapping into the scheduled updates of cocos2d from this non-cocos2d class, or somehow otherwise pushing user input information from the joystick class to cocos2d.
Possibly you can create an UIView and put it over the opengl view. To access the openglView use [CCDirector sharedDirector].openGLView. Create your joystick using UIView. So it will be always shown, and will be not affected by CCScene transitions.