Does Xcode 11.2 scene editor allow adding components? - ios

Using Xcode 11.2 I can create a new project using the "Game" template. I can include for "Game Technology" SpriteKit and check "Integrate GameplayKit". If I run the code at this point on an iPhone 11 Pro iOS 13.2 simulator I see the "Hello, World!" label. If I go into the Library and add a Color Sprite at position (0,0) to the GameScene.sks file when I run I see the red Color Sprite. My problem comes when I add a Swift file with the content
import GameplayKit
class MovementComponent : GKComponent {
override func update(deltaTime seconds: TimeInterval) {
print(seconds)
}
}
and use the components editor in Xcode to add this component to the Color Sprite. When I run this I get a grey screen. When I check the GameViewController file I see with the debugger that scene.rootNode is nil. What's going wrong? I just want to see how to integrate a component with a Color Sprite using the components editor. Does this stuff work at all or is this just for WWDC demos?

Appears to be a bug in Xcode 11.2. Following the steps above the behavior appears correct for Xcode 10.3. Filled out Apple Feedback FB7427190. Thanks Knight0fDragon for helping identify where the problem was.

I guess my post today is a duplicate of this post.
SKScene not loaded when add GKComponent to GameScene.sks
It seems that the problem still exist in Xcode 11.3.1
If there is no component added in the scene editor to a SKSpriteNode I see that the scene is completely loaded as GameScene.sceneDidLoad is called.
If there is a GKComponent added in the scene editor. The GameScene is not loaded - GameScene.sceneDidLoad is never called.

Related

Xcode's SceneKit editor renders .dae file's wrong and Xcode sometimes crashes during preview

I'm trying to figure out how to import .dae files with animations into Xcode and SceneKit.
It works somewhat, but it's really buggy, I can't preview files, and Xcode sometimes crashes when trying to preview the .dae files in Xcode.
Here's how I'm importing the animated models
I download an animated character from Mixamo, as a Collada file, with the settings below.
Create a brand new SceneKit iOS project, import .dae file, and select the file in the Xcode file list to preview it. The result can be seen below. I have zoomed all the way out to make sure I'm not just viewing the model from the inside of the mesh. The lines extend infinetly it looks like.
If I use the ConvertToXcodeCollada workflow, and verify that the .dae XML only has one <animation> tag with corresponding closing tag, and then import it into Xcode, it won't open at all. See image below.
If I import the .dae file version not converted using ConvertToXcodeCollada, and the add .dae file as a sub reference in a .scn Scene file, the model displays correctly, and the animation is playing correctly. Image below.
So how should I do this properly?
I have also tried to import animated models into Blender and then export it to Collada from there (with unstructions from tutorials on youtube), and same results. Is there a way I can do this a proper way, where it works like it should, without Xcode behaving buggy? It would be easier if I could actually preview and edit materials etc of the .dae files directly, without having to always add them to an existing .scn Scene Kit Scene.
I did followed your instructions and try to load a 3D animation. Its working fine for me
In new sceneKit project I have updated my code like.
// create a new scene
let scene = SCNScene(named: "Jumping.dae")! //"art.scnassets/ship.scn")!
and this too
let ship = scene.rootNode.childNode(withName: "mixamorig_Hips", recursively: true)! // "ship"
I am using XCode 10.1 on macOS 10.13.6
This happen when I try to open in finder a .dae file with animation created with mixamo
https://www.mixamo.com/#/
mojave OS 10.14.1
BUG Fixed by apple 10.14.2
I have downloaded which you mentioned above link. github.com/eh3rrera/ARKitAnimation
And I opened in finder. Its working for my mac

SpriteKit .sks Files Crash Xcode 10 When Assigning Texture

Am I missing something obvious?
For reasons unknown, Xcode 10 keeps crashing on me when I go to assign a texture to a named sprite using the Scene Editor. After having to delete and recreate my .sks files a couple times, I decided to try and reproduce the issue using Xcode's game template. The steps I took to do this are as follows:
Open Xcode and select Create a new Xcode project.
Choose the Game template, name the project Test and save it somewhere, i.e. your desktop.
Drag any image asset into Assets.xcassets. I used this green square:
Open GameScene.sks and drag a Color Sprite onto the scene.
Name the sprite something descriptive like square_green.
Attempt to set the texture in this field:
Other similar questions on Stack Overflow:
Xcode is crashing in SpriteKit
XCode 9 Crashing while setting a Texture in SKScene in Spritekit
If I do not set a name for the color sprite prior to assigning a texture, everything works fine. However, if Xcode is forced to crash at least one time, I have to delete the .sks file completely just to get Xcode to open again.
For the time being I've decided to avoid the trouble all together and just assign the textures programmatically in the didMove(to:) of my SKScene class:
override func didMove(to view: SKView) {
let greenSquare = childNode(withName: "square_green") as! SKSpriteNode
greenSquare.texture = SKTexture(imageNamed: "square_green")
}
I ran into the same problem, and later I moved the images out of Assets.xcassets and the problem was solved. I guess the image can't be placed in Assets.xcassets.

How to set preferredRenderingAPI for ARSCNView in Xcode IB

In my ARKit application ARSCNView is initialized and attached to ViewController internally based on storyboard file structure. So in function viewDidLoad I have already initialized view.
But the problem is it uses default rendering API metal. But I would like to change it to OpenGL ES2. In Apple documentation I read that preferredRenderingAPI can be somehow changed in IB inspector. But I don't understand how. There are no any examples of how to do this?
Or maybe I still change it from the code, even though the view is initialized from IB?
Just open your Main.storyboard (or whatever you have) in Xcode and navigate to the node Scene View of type SCNView in there. The Attributes inspector should allow you to change the renderer (Rendering API).
I've just tested it but it looked like my project didn't work the same as with metal.

SpriteKit on AppleWatch - How to present a scene?

I made a game for iOS using SpriteKit.
Now I wanna make also the version for watchOS.
I added a new target and then these files appear to me:
If I delete the sks file and then try to present a swift scene as I did for the iOS game the scene appears empty... So the only thing i could do is leave the scene.sks file as it was.
Can someone kindly explain to me how can to present a new scene.swift file in the interfaceController.swift without using the sks file?
Here is the InterfaceController.swift file that presents the sks scene, but I wanna present my own swift scene.
Best Regards.
exchange the GameScene(filenamed:) with `YourScene(size:).
Your scenes are a subclass of SKView which have their primary initializers... here is the link to the one I showed:
https://developer.apple.com/reference/spritekit/skscene/1520435-init
So (filenamed:) is one initializer (for .sks) and (size:) is another initializer, for not having .sks. These initializers are the exact same kind of initializers you use for all of your own classes.
This just isn't readily apparent, because when you make your own GameScene: SKScene you don't specify initializers (because they are inherited from SKScene that you just subclassed from)
the video below also covers most of the necessary things for SK on AW.. it's timestamped to explain more of what you're doing:
https://youtu.be/REv-w2rBsng?t=1173
the info in the above video is virtually nowhere else that I could find, so I highly recommend you watch it from begin to end.
NOTE:
(last I checked)
Your vanilla SKScenes won't work on the watch, because they lack certain functions (like touchesBegan) because you are no longer using an SKView to present your scene. So, you must use gesture recognizers..
Here explains how to get around that stuff:
TouchEvents in watchOS 3 SpriteKit?

IBDesignable Not Working Xcode 7 Swift 2 (core graphics)

The IBDesignable property seems to be not working on Xcode 7 using swift 2. Below is my custom class to draw a button.
#IBDesignable class PushButtonView: UIButton {
override func drawRect(rect: CGRect) {
let path = UIBezierPath(ovalInRect: rect)
UIColor.greenColor().setFill()
path.fill()
}
the code is running in the simulator. (See image 1) I have also attached a screenshot of the storyboard (see image 2) Not sure if some settings need to be changed
I had the same issue with "Mixpanel" CocoaPod.
You can check if everything is compiling for the interface builder in the Report Navigator (Left pane, the right-most tab). Click on "By Group" to filter content and look at the "Interface Builder" section. You will see there if something went wrong while compiling with the ibtool. In my case mixpanel survey widget was not compiling.
I simply removed the pod from the podfile, did pod install and could work on my custom view. Once done with the custom view i added mixpanel to the podfile again. Hope this helps
Click Editor > Refresh All Views after you make the changes.
Alternatively, you can also select Editor > Automatically Refresh Views, but I find that sometimes buggy and may not consistently.

Resources