I've created a ".sks" file.
I've configured the effect in the editor.
I've added import SpriteKit in a swift view file.
Apple's documentation shows this snippet (but I don't know how to use it properly):
func newSmokeEmitter() -> SKEmitterNode? { return SKEmitterNode(fileNamed: "smoke.sks") }
I've seen this and this, but they didn't solve my problem either. Does SpriteKit require that you configure your app as a) a game and b) SpriteKit, or can it be done in my single-page app? Thanks for your help!
Related
I have a Reality Composer file with several scenes, all of which starts empty and then some models appear one by one every second. Even though the animation works perfectly in Quicklook and Reality Composer, it does a strange glitch when I try to integrate it in my app with Xcode. When the very first scene is launched or when we go to another scene, they don't start empty.. For a tiny split second, we see all the models of that scene being displayed, only to disappear immediately.
Then, we see them appearing slowly as they were supposed to. That tiny flash of models at the beginning of each scene is ruining everything. I tried using a .reality file and a .rcproject file, same problem. In fact, when we preview the animation of the Reality file inside Xcode, it does the same glitch. I tried using different Hide and Show functions, no change.. I tried different triggers such as notifications, scene start, on tap, no change.
I checked quite some tutorials and still couldn't find anything wrong in what I'm doing. I almost feel like there is a glitch in the current integration of Reality Composer. I would really appreciate some ideas on the subject...
Try this to prevent a glimpse...
import UIKit
import RealityKit
class ViewController: UIViewController {
#IBOutlet var arView: ARView!
var box: ModelEntity!
override func viewDidLoad() {
super.viewDidLoad()
let scene = try! Experience.loadScene()
self.box = scene.cube!.children[0] as? ModelEntity
self.box.isEnabled = false
arView.scene.anchors.append(scene)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.box.isEnabled = true
}
}
}
In such a scenario glitching occurs only for sphere. Box object works fine.
#AndyJazz Thanks. This solution works for me. Alternately to the line :
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.box.isEnabled = true
I suggest (while in Reality Composer) Create a Behavior with:
Trigger Scene Start
Action Show
The appearance of the entity can then also be tweaked with a Motion Type, Ease Type and Style as well as chained to additional sequences.
I am using vuforia & ARKit sdk in my application.
I have two buttons ( Vuforia & ARKit buttons)
My app work flow:
Open the app
Clicked on “vuforia AR” button (1st time)
If marker found Vuforia AR works.
i am switch to “ARKit” 1st time, it will be working fine.
If we press back button, it will redirect to MainScreen
Again Click on “vuforia AR” button (2nd time)
Vuforia working good.
If we switch to “ARKit” , ARKit Camera is not resetting .
Here arkit camera is freezing.
Note: both SDK are using single scene and I tried two different scenes also. My issue is not resolved.
Don't know if you solved your problem.
If not, did you tried to reset your ARKit scene ?
Here's a sample code I founded in another post. Working fine for me to reset my ARKit Session.
public void ResetScene()
{
ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(UnityARAlignment.UnityARAlignmentGravity, UnityARPlaneDetection.Horizontal);
UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking);
}
Don't forget to change sessionConfig parameters with yours ! ;)
I am using the following code in iOS 10.0 in my GameScene.swift
//Shape storage
let playerShape = SKShapeNode(circleOfRadius: 10 )
...Color setup etc
//Get the texture from shape node
let playerTexture = view?.texture(from: playerShape)
The same code doesn't work in watchOS 3.0
Xcode 8.0 beta 2 complaints about the view:
Use of unresolved identifier 'view'
Does anyone know whats the equivalent of view in watchOS?
Thank you.
As mentioned above there are no views in Apple Watch's Sprite Kit.
So that is why you are unable to use view in your code.
Just use SKSpriteNode instead and do something like this if you want the texture for something else.
E.g. here I want to use my circleOriginal texture on circle 2
let circleOriginal = SKSpriteNode(imageNamed: "circle")
let circleTexture = circleOriginal.texture
let circle2 = SKSpriteNode(texture: circleTexture)
If you want an amazing overview of Apple Watch Game Tech check out Apple's WWDC lecture on it (The slides below are from there). This explains a lot and provides great code examples.
https://developer.apple.com/videos/play/wwdc2016/612/
Here are the key differences.
Here's Apple's Scene Graph for non-watchOS
Here's Apple's Scene Graph corresponding Scene Graph for watchOS
Here are the recommended alternatives for watchOS's SpriteKit / SceneKit
Currently I'm using Application.load() to change scenes and it works perfectly in Unity. When I built it to a mobile platform and tested it, only in that one scene I can't change to a specific scene.
For example, gameplayScene, levelSelectionScene, mainMenu. I'm able to change scene from mainMenu to levelSelectionScene and then to gameplayScene. For unknown reason, I'm unable to go back to levelSelectionScene from gameplayScene while I can change scene to mainMenu from gameplayScene.
Below is the sample code from button that goes to levelSelectionScene from gameplayScene
private void OnClick ()
{
Debug.Log ("clicked");
if (PlayerPrefs.GetInt("SanguineDifficultyAchieved") == 1)
{
Debug.Log("Entering Difficulty");
m_Owner.SetActive ();
}
else
{
Debug.Log("Exiting");
State.Current = State.NotInGame;
Application.LoadLevel(scene.name);
}
m_Owner.close ();
I don't understand why it works on Unity debugger but then it doesn't work on mobile platforms.
Update 1
I tried to use numbers instead of strings it worked well. But I still don't understand the reason why.
Finally got an answer. It seems that the scenes collided with each other because I use scenes from Asset Bundle and the added scenes from build settings. That is why the when i use Application.Load(int number) works because i only access the scene from build settings.
I'm making a game with Swift and Sprite Kit.
I would like to add background music and sound effects.
The "classic" way is to use AVFoundation, but this does not seem to have new Swift APIs, only Objective C ones.
Is there a new modern swift sound API I can use with Sprite Kit easily?
No frameworks have new Swift APIs in iOS 8 or OS X Yosemite. All Objective-C frameworks are automatically bridged to Swift, and those include both SpriteKit and AVFoundation.
If you're looking for a quick high-level alternative to the more detailed AVFoundation APIs for adding sounds and music to your game, look no further than SpriteKit itself. (Regardless of whether you use Swift or Objective-C.)
SKAction provides a playSoundFileNamed:waitForCompletion: action. Pass false for the second parameter to play sound effects, or pass true and make a repeating action to loop music.