SpriteKit

RSS for tag

Drawing shapes, particles, text, images, and video in two dimensions using SpriteKit.

SpriteKit Documentation

Posts under SpriteKit subtopic

Post

Replies

Boosts

Views

Activity

Unable to Install Tap on Input Node in MacOS for Live Audio Speech Recognition
I'm developing a game that will use speech recognition to execute various commands. I am using code from Apple's Recognizing Speech in Live Audio documentation page. When I run this in a Swift Playground, it works just fine. However, when I make a SpriteKit game application (basic setup from Xcode's "New Project" menu option), I get the following error: required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat) Upon further research, it appears that my input node has no channels. The following is the relevant portion of my code, along with debug output: let inputNode = audioEngine.inputNode print("Number of inputs: \(inputNode.numberOfInputs)") // 1 print("Input Format: \(inputNode.inputFormat(forBus: 0))") // <AVAudioFormat 0x600001bcf200: 0 ch, 0 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved> let channelCount = inputNode.inputFormat(forBus: 0).channelCount print("Channel Count: \(channelCount)") // 0 <== Agrees with the inputFormat output listed previously // Configure the microphone input. print("Number of outputs: \(inputNode.numberOfOutputs)") // 1 let recordingFormat = inputNode.outputFormat(forBus: 0) print("Output Format: \(recordingFormat)") // <AVAudioFormat 0x600001bf3160: 2 ch, 44100 Hz, Float32, non-inter> inputNode.installTap(onBus: 0, bufferSize: 256, format: recordingFormat, block: audioTap) // <== This is where the error occurs. // NOTE: 'audioTap' is a function defined in this class. Using this defined function instead of an inline, anonymous function. The code snippet is included in the game's AppDelegate class (which includes import statements for Cocoa, AVFoundation, and Speech), and executes during its applicationDidFinishLaunching function. I'm having trouble understanding why Playground works, but a game app doesn't work. Do I need to do something specific to get the application to recognize the microphone? NOTE: This if for MacOS, NOT iOS. While the "How To" documentation cited earlier indicates iOS, Apple stated at WWDC19 that it is now supported on the MacOS. NOTE: I have included the NSSpeechRecognitionUsageDescription key in the applications plist, and successfully acknowledged the authorization request for the microphone.
1
0
2.7k
Dec ’21
SpriteKit SKScene Can't Find SKS File
I'm toying around with SpriteKit and using SKS files to construct scenes. I've started with the stock Game project and added one extra SKS file and a class to go along with it. My class will attempt to load the SKS file to build its scene just like the stock files do. However, when I go to the GameViewController and actually try to use my class, I get a runtime error that my SKS file can't be found. I've verified that the SKS file is in the project, is part of the bundle, is visible at runtime from within the bundle, but my class that uses the SKScene initializer to load the file can't see it and I'm not sure why.
0
0
509
Dec ’21
How to handle touch event when use SwiftUI & SpriteView on watchOS 8
I want to learning make a sample game on Apple Watch which install watchOS 8. I use SwiftUI to wrap the SpriteView for displaying the game scene. All work fine except handling the touch event. When I override the function " touchesEnded " in GameScene, it report error for no such function on watchOS. How to handle the tap event on watchOS ? Any suggestion is welcome, thank you. struct ContentView: View {     var sz = WKInterfaceDevice.current().screenBounds.size     var scene: SKScene {         let scene = GameScene()         scene.size = sz         scene.scaleMode = .resizeFill         return scene     }          var body: some View {         SpriteView(scene: scene)             .frame(width: sz.width, height: sz.height)             .ignoresSafeArea()     } } class GameScene: SKScene {     override func sceneDidLoad() {         print("sceneDidLoad size=\(size.width),\(size.height)")         myInit()     }   override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { // build error for no touchesEnded func on watchOS } }
0
0
524
Dec ’21
SKShapeNode bad Performance
While learning and playing around with Swift and Spritekit i run into an issue: I can´t seem to create many SKShapeNodes at Runtime. I am trying to fill the Screen with "random" Triangles (The green Triangle on top is just a "dummy" Triangle moving from the left to the right so i get to see the FPS) These brown-ish Triangles are SKShapeNodes created like this: func createTwoFloorTrianglesAtLocation(xPos:CGFloat, yPos:CGFloat, width:CGFloat, height:CGFloat, orientation:Bool) -> [SKShapeNode] { let path1 = UIBezierPath() let path2 = UIBezierPath() if orientation { path1.move(to: CGPoint(x: xPos, y: yPos)) path1.addLine(to: CGPoint(x: xPos, y: yPos + height)) path1.addLine(to: CGPoint(x: xPos + width, y: yPos)) path2.move(to: CGPoint(x: xPos + width, y: yPos)) path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) path2.addLine(to: CGPoint(x: xPos, y: yPos + height)) } else { path1.move(to: CGPoint(x: xPos, y: yPos)) path1.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) path1.addLine(to: CGPoint(x: xPos, y: yPos + height)) path2.move(to: CGPoint(x: xPos + width, y: yPos)) path2.addLine(to: CGPoint(x: xPos, y: yPos)) path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) } let triangle1 = SKShapeNode(path: path1.cgPath) triangle1.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]! triangle1.name = "colorSprite" triangle1.lineWidth = 0.0 let triangle2 = SKShapeNode(path: path2.cgPath) triangle2.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]! triangle2.name = "colorSprite" triangle2.lineWidth = 0.0 return [triangle1, triangle2] } I add these Triangles calling #addChild(SKNode) to the GameScene. These Triangles don´t move or anything, they are supposed to disappear later in the Game by "drawing lines" above them. The Problem is that i get very bad FPS and a high CPU-Usage as well as a high Power-Usage in both the XCode-Simulator and on a real Device (iPhone 13 Pro Max, too). If i reduce the Amount of Triangles it gets better, but i´d like to not do that. Is there any way to fix this issue? I also read online (https://stackoverflow.com/questions/23461966/create-an-sktexture-from-an-skshapenode) that some use SKSpriteNode instead of SKShapeNode. But if use the following code to "convert" my ShapeNodes to SpriteNodes before adding them as a Child to the Scene, i see the Node-Counter in the Bottom left is also around 1000ish but there are no Rectangles rendered. func addNodesToParent(_ stuff:[SKShapeNode]) { for n in stuff { addChild(SKSpriteNode(texture: self.view?.texture(from: n))) //addChild(n) } } I hope someone has an idea that i can try. Thanks in advance, Greetings, Nico
1
0
979
Dec ’21
Spritekit as material of SCNnode.. crash.. bad
What I'm try to do, is replicate some digital instrument gauge ...using Spritekit.. On my project I have to use a SpriteKit Scene as material for Scenekit SCNnode. In order to do that I create a sub class of SKscene and and apply it as "material.diffuse.contents" of the SCNNode. all working fine, I can see my SKscene as material of the SCNNode. Here the issue: I try to animate/replicate the correct indication of the instrument based of some value my app received from other source. To do so, i decide to use the SKsceneDelegate and use the method "update(_ currentTime: TimeInterval)" simply the update method look for the sknode of the green needle "fulcro" remove it , and make a new line calculating the angle and new coordinate for the new line. Like this I should have a smooth needle indication... Here is the update method inside my subclass SKscene: override func update(_ currentTime: TimeInterval) {                  guard let fulcroToRemove = self.childNode(withName: "fulcro") else {return}         fulcroToRemove.removeFromParent() // issue here...          let fulcro = SKNode()         fulcro.name = "fulcro"         fulcro.position = CGPoint(x: 300, y: 260)         let line = makeLine(startPos: CGPoint(x: 0, y: 0),                             endPos: getCoordinate(angleDeg: getCurrentEGT()),                             name: "EGT_LINE")         fulcro.addChild(line)         self.addChild(fulcro)     } here how I apply the material SKscene to my SCNnode class LowerECAM : SCNNode {     var systems: PlaneSystems     init(systems: PlaneSystems) { self.systems = systems         super.init()         createLowerECAM()     }     required init?(coder: NSCoder) {         fatalError("init(coder:) has not been implemented for Make Cockpit")     }     func createLowerECAM(){ systems.lowerECAMView.presentScene(systems.newAPU)         let plane = SCNPlane(width: 1, height: 1)         let material = SCNMaterial()         material.isDoubleSided  = true         material.diffuse.contents = systems.lowerECAMView.scene // apply here plane.materials = [material]         let lowerECAM = SCNNode(geometry: plane)         lowerECAM.eulerAngles = SCNVector3(deg2rad(180), deg2rad(90), 0)         lowerECAM.scale = SCNVector3(3.3, 3.3, 3.3)         self.name = "LowerECAM"         self.addChildNode(lowerECAM)     }     func deg2rad(_ number: Double) -> Double {         return number * .pi / 180     }   func rad2deg(_ number: Double) -> Double {         return number * 180 / .pi     } } But.. I'm getting the following crash: Question?? why scene kit crash when the render I'm using is the Spritekit render.. ?? I did't even write the SceneKit render method.. The issue looks like is when I remove the "fulcro" but I can't find the solution. I tried to make a new project only with spritekit and it works perfect.. can't understand why as material of SCNode it crash. Any Suggestion.. Appreciate.. Thanks a lot
0
0
1.1k
Dec ’21
Drag and Drop Activity
Hello, please excuse this question if it seems too simple.. I am new to this and trying to learn :). Im after developing a children's app where the child would drag items into place for example images of numbers being placed in the correct drop areas etc. I don't want to use Unity for this and im keen to learn native swift... Any tips, pointers or starting points would be really welcome for this project please. Be Gentle I am totally new to this! :) Chris
1
0
517
Dec ’21
SKEmitterNode ignoring zPosition on iOS
When compiling and testing an old game (Paul Pixel - The Awakening) on the latest Xcode 12.3 for the latest iOS 14.3, the Spritekit particles appeared on top. The SKEmitterNode.zPosition value was ignored. I regularly compile the app with Xcode. So this regression happened with either iOS 14.2 or Xcode 12.2. It doesn't happen when compiling for macOS. The bug is on iOS only. Does anybody have the same problem? I have already reported the bug to Apple, but they're not responding.
3
0
1.2k
Nov ’21
How do I call scenes without using sks files in Objective-C?
I'm certain this has been asked before, but I do not want to use sks files. I have some very old Cocos2d code that I'm trying to port without a complete rewrite. I would rather programatically move my scene sprites around based on the screensize and do it in Obj-C. It is unclear to me how to do this. I sort of found an answer here: https://stackoverflow.com/questions/43927323/are-spritekit-scene-sks-files-necessary-in-my-project Tried to do something equivalent in Obj-C, but got no where.
1
0
710
Nov ’21
Sound effects in SpriteKit - memory and frame rate issues
I am working on my first game. I was using SKAction.playSoundFileNamed() to play .wav files in my assets, but this was causing problematic memory use growth. After looking online and reading that method has been linked to leaks, I switched to SKAudioNodes. I have added many of those to my scene, and they work, but the frame rate is lower now than before. Any suggestions? I had used this (but I had memory usage growing): let hiss = SKAction.playSoundFileNamed("hiss.wav", waitForCompletion: false) run(hiss) Now I have this (but frame rates are down): let hiss: SKAudioNode = SKAudioNode(fileNamed: "hiss.wav") hiss.autoplayLooped = false hiss.isPositional = false addChild(hiss) hiss.run(SKAction.play())  Any tips?
1
0
848
Nov ’21
SpriteKit draw calls not batched when using a texture atlas from data stored in the app bundle
It seems that SpriteKit doesn't batch the draw calls for textures in the same texture atlas. There are two different behaviors, based on how the SKTextureAtlas gets initialized: The draw calls are not batched when the texture atlas is initialized using SKTextureAtlas(named:) (loading the texture atlas from data stored in the app bundle). But the draw calls seem to be batched when the texture atlas is created dynamically using SKTextureAtlas(dictionary:). The following images show the two different behaviors and the SpriteAtlas inside the Assets Catalog. 1. Draw calls not batched: 2. Draw calls batched: The SpriteAtlas: I created a sample Xcode 13 project to show the different behavior: https://github.com/clns/spritekit-atlas-batching. I have tried this on the iOS 15 simulator on macOS Big Sur 11.6.1. The code to reproduce is very simple: import SpriteKit class GameScene: SKScene { override func didMove(to view: SKView) { let atlas = SKTextureAtlas(named: "Sprites") // let atlas = SKTextureAtlas(dictionary: ["costume": UIImage(named: "costume")!, "tank": UIImage(named: "tank")!]) let costume = SKSpriteNode(texture: atlas.textureNamed("costume")) costume.setScale(0.3) costume.position = CGPoint(x: 200, y: 650) let tank = SKSpriteNode(texture: atlas.textureNamed("tank")) tank.setScale(0.3) tank.position = CGPoint(x: 500, y: 650) addChild(costume) addChild(tank) } } Am I missing something?
1
0
1.4k
Nov ’21
Rendering issues (objects blurred, frame dimensions = 1) when SKScene is inside SwiftUI context
I am developing an app that contains a SpriteKit scene embedded inside a SwiftUI context.I am trying to render a simple SKShapeNode like this:import Foundation import SpriteKit class UIConnection: SKShapeNode { override init() { super.init() self.fillColor = UIColor.clear self.strokeColor = UIColor.blue self.lineWidth = 0.01 } func updatePositions(node1 : CGPoint, node2 : CGPoint) { let path = CGMutablePath() path.move(to: node1) path.addLine(to: CGPoint(x: node1.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node1.y)) path.addLine(to: node1) self.path = path } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } }When I am adding that Node inside the standard SpriteKit game project template in XCode (without any SwiftUI things), everything is working fine, I get a non-filled rectangle with a blue outline. The frame.width and frame.height variables are valid pixel dimensions like 750 x 1334.let node = UIConnection() self.addChild(node) node.updatePositions(node1: CGPoint(x: frame.midX-frame.width/4, y: frame.midY-frame.height/4), node2: CGPoint(x: frame.midX+frame.width/4, y: frame.midY+frame.height/4))Now I want to embed the SKScene inside a SwiftUI context using this approach:https://dev.to/sgchipman/using-spritekit-with-swiftui-ibcFirst thing I encounter is the fact that frame.width and frame.height both result in a value of 1.Adding the above node to the embedded SKScene results in an extremely blurred rectangle, so no solid line but some weird cloudy object.
1
0
1.1k
Nov ’21
Unable to Install Tap on Input Node in MacOS for Live Audio Speech Recognition
I'm developing a game that will use speech recognition to execute various commands. I am using code from Apple's Recognizing Speech in Live Audio documentation page. When I run this in a Swift Playground, it works just fine. However, when I make a SpriteKit game application (basic setup from Xcode's "New Project" menu option), I get the following error: required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat) Upon further research, it appears that my input node has no channels. The following is the relevant portion of my code, along with debug output: let inputNode = audioEngine.inputNode print("Number of inputs: \(inputNode.numberOfInputs)") // 1 print("Input Format: \(inputNode.inputFormat(forBus: 0))") // <AVAudioFormat 0x600001bcf200: 0 ch, 0 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved> let channelCount = inputNode.inputFormat(forBus: 0).channelCount print("Channel Count: \(channelCount)") // 0 <== Agrees with the inputFormat output listed previously // Configure the microphone input. print("Number of outputs: \(inputNode.numberOfOutputs)") // 1 let recordingFormat = inputNode.outputFormat(forBus: 0) print("Output Format: \(recordingFormat)") // <AVAudioFormat 0x600001bf3160: 2 ch, 44100 Hz, Float32, non-inter> inputNode.installTap(onBus: 0, bufferSize: 256, format: recordingFormat, block: audioTap) // <== This is where the error occurs. // NOTE: 'audioTap' is a function defined in this class. Using this defined function instead of an inline, anonymous function. The code snippet is included in the game's AppDelegate class (which includes import statements for Cocoa, AVFoundation, and Speech), and executes during its applicationDidFinishLaunching function. I'm having trouble understanding why Playground works, but a game app doesn't work. Do I need to do something specific to get the application to recognize the microphone? NOTE: This if for MacOS, NOT iOS. While the "How To" documentation cited earlier indicates iOS, Apple stated at WWDC19 that it is now supported on the MacOS. NOTE: I have included the NSSpeechRecognitionUsageDescription key in the applications plist, and successfully acknowledged the authorization request for the microphone.
Replies
1
Boosts
0
Views
2.7k
Activity
Dec ’21
SpriteKit SKScene Can't Find SKS File
I'm toying around with SpriteKit and using SKS files to construct scenes. I've started with the stock Game project and added one extra SKS file and a class to go along with it. My class will attempt to load the SKS file to build its scene just like the stock files do. However, when I go to the GameViewController and actually try to use my class, I get a runtime error that my SKS file can't be found. I've verified that the SKS file is in the project, is part of the bundle, is visible at runtime from within the bundle, but my class that uses the SKScene initializer to load the file can't see it and I'm not sure why.
Replies
0
Boosts
0
Views
509
Activity
Dec ’21
How to handle touch event when use SwiftUI & SpriteView on watchOS 8
I want to learning make a sample game on Apple Watch which install watchOS 8. I use SwiftUI to wrap the SpriteView for displaying the game scene. All work fine except handling the touch event. When I override the function " touchesEnded " in GameScene, it report error for no such function on watchOS. How to handle the tap event on watchOS ? Any suggestion is welcome, thank you. struct ContentView: View {     var sz = WKInterfaceDevice.current().screenBounds.size     var scene: SKScene {         let scene = GameScene()         scene.size = sz         scene.scaleMode = .resizeFill         return scene     }          var body: some View {         SpriteView(scene: scene)             .frame(width: sz.width, height: sz.height)             .ignoresSafeArea()     } } class GameScene: SKScene {     override func sceneDidLoad() {         print("sceneDidLoad size=\(size.width),\(size.height)")         myInit()     }   override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { // build error for no touchesEnded func on watchOS } }
Replies
0
Boosts
0
Views
524
Activity
Dec ’21
touchesBegan for tvOS in the game?
I have a game with SpriteKit for iPhone, iPad and Mac. I am gonna make for Apple TV. But I take it override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { doesn't work for tvOS. Then what I am supposed to use to make my buttons selectable and I can press ones?
Replies
2
Boosts
0
Views
787
Activity
Dec ’21
SKShapeNode bad Performance
While learning and playing around with Swift and Spritekit i run into an issue: I can´t seem to create many SKShapeNodes at Runtime. I am trying to fill the Screen with "random" Triangles (The green Triangle on top is just a "dummy" Triangle moving from the left to the right so i get to see the FPS) These brown-ish Triangles are SKShapeNodes created like this: func createTwoFloorTrianglesAtLocation(xPos:CGFloat, yPos:CGFloat, width:CGFloat, height:CGFloat, orientation:Bool) -> [SKShapeNode] { let path1 = UIBezierPath() let path2 = UIBezierPath() if orientation { path1.move(to: CGPoint(x: xPos, y: yPos)) path1.addLine(to: CGPoint(x: xPos, y: yPos + height)) path1.addLine(to: CGPoint(x: xPos + width, y: yPos)) path2.move(to: CGPoint(x: xPos + width, y: yPos)) path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) path2.addLine(to: CGPoint(x: xPos, y: yPos + height)) } else { path1.move(to: CGPoint(x: xPos, y: yPos)) path1.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) path1.addLine(to: CGPoint(x: xPos, y: yPos + height)) path2.move(to: CGPoint(x: xPos + width, y: yPos)) path2.addLine(to: CGPoint(x: xPos, y: yPos)) path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height)) } let triangle1 = SKShapeNode(path: path1.cgPath) triangle1.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]! triangle1.name = "colorSprite" triangle1.lineWidth = 0.0 let triangle2 = SKShapeNode(path: path2.cgPath) triangle2.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]! triangle2.name = "colorSprite" triangle2.lineWidth = 0.0 return [triangle1, triangle2] } I add these Triangles calling #addChild(SKNode) to the GameScene. These Triangles don´t move or anything, they are supposed to disappear later in the Game by "drawing lines" above them. The Problem is that i get very bad FPS and a high CPU-Usage as well as a high Power-Usage in both the XCode-Simulator and on a real Device (iPhone 13 Pro Max, too). If i reduce the Amount of Triangles it gets better, but i´d like to not do that. Is there any way to fix this issue? I also read online (https://stackoverflow.com/questions/23461966/create-an-sktexture-from-an-skshapenode) that some use SKSpriteNode instead of SKShapeNode. But if use the following code to "convert" my ShapeNodes to SpriteNodes before adding them as a Child to the Scene, i see the Node-Counter in the Bottom left is also around 1000ish but there are no Rectangles rendered. func addNodesToParent(_ stuff:[SKShapeNode]) { for n in stuff { addChild(SKSpriteNode(texture: self.view?.texture(from: n))) //addChild(n) } } I hope someone has an idea that i can try. Thanks in advance, Greetings, Nico
Replies
1
Boosts
0
Views
979
Activity
Dec ’21
Spritekit as material of SCNnode.. crash.. bad
What I'm try to do, is replicate some digital instrument gauge ...using Spritekit.. On my project I have to use a SpriteKit Scene as material for Scenekit SCNnode. In order to do that I create a sub class of SKscene and and apply it as "material.diffuse.contents" of the SCNNode. all working fine, I can see my SKscene as material of the SCNNode. Here the issue: I try to animate/replicate the correct indication of the instrument based of some value my app received from other source. To do so, i decide to use the SKsceneDelegate and use the method "update(_ currentTime: TimeInterval)" simply the update method look for the sknode of the green needle "fulcro" remove it , and make a new line calculating the angle and new coordinate for the new line. Like this I should have a smooth needle indication... Here is the update method inside my subclass SKscene: override func update(_ currentTime: TimeInterval) {                  guard let fulcroToRemove = self.childNode(withName: "fulcro") else {return}         fulcroToRemove.removeFromParent() // issue here...          let fulcro = SKNode()         fulcro.name = "fulcro"         fulcro.position = CGPoint(x: 300, y: 260)         let line = makeLine(startPos: CGPoint(x: 0, y: 0),                             endPos: getCoordinate(angleDeg: getCurrentEGT()),                             name: "EGT_LINE")         fulcro.addChild(line)         self.addChild(fulcro)     } here how I apply the material SKscene to my SCNnode class LowerECAM : SCNNode {     var systems: PlaneSystems     init(systems: PlaneSystems) { self.systems = systems         super.init()         createLowerECAM()     }     required init?(coder: NSCoder) {         fatalError("init(coder:) has not been implemented for Make Cockpit")     }     func createLowerECAM(){ systems.lowerECAMView.presentScene(systems.newAPU)         let plane = SCNPlane(width: 1, height: 1)         let material = SCNMaterial()         material.isDoubleSided  = true         material.diffuse.contents = systems.lowerECAMView.scene // apply here plane.materials = [material]         let lowerECAM = SCNNode(geometry: plane)         lowerECAM.eulerAngles = SCNVector3(deg2rad(180), deg2rad(90), 0)         lowerECAM.scale = SCNVector3(3.3, 3.3, 3.3)         self.name = "LowerECAM"         self.addChildNode(lowerECAM)     }     func deg2rad(_ number: Double) -> Double {         return number * .pi / 180     }   func rad2deg(_ number: Double) -> Double {         return number * 180 / .pi     } } But.. I'm getting the following crash: Question?? why scene kit crash when the render I'm using is the Spritekit render.. ?? I did't even write the SceneKit render method.. The issue looks like is when I remove the "fulcro" but I can't find the solution. I tried to make a new project only with spritekit and it works perfect.. can't understand why as material of SCNode it crash. Any Suggestion.. Appreciate.. Thanks a lot
Replies
0
Boosts
0
Views
1.1k
Activity
Dec ’21
Drag and Drop Activity
Hello, please excuse this question if it seems too simple.. I am new to this and trying to learn :). Im after developing a children's app where the child would drag items into place for example images of numbers being placed in the correct drop areas etc. I don't want to use Unity for this and im keen to learn native swift... Any tips, pointers or starting points would be really welcome for this project please. Be Gentle I am totally new to this! :) Chris
Replies
1
Boosts
0
Views
517
Activity
Dec ’21
SKEmitterNode ignoring zPosition on iOS
When compiling and testing an old game (Paul Pixel - The Awakening) on the latest Xcode 12.3 for the latest iOS 14.3, the Spritekit particles appeared on top. The SKEmitterNode.zPosition value was ignored. I regularly compile the app with Xcode. So this regression happened with either iOS 14.2 or Xcode 12.2. It doesn't happen when compiling for macOS. The bug is on iOS only. Does anybody have the same problem? I have already reported the bug to Apple, but they're not responding.
Replies
3
Boosts
0
Views
1.2k
Activity
Nov ’21
How do I call scenes without using sks files in Objective-C?
I'm certain this has been asked before, but I do not want to use sks files. I have some very old Cocos2d code that I'm trying to port without a complete rewrite. I would rather programatically move my scene sprites around based on the screensize and do it in Obj-C. It is unclear to me how to do this. I sort of found an answer here: https://stackoverflow.com/questions/43927323/are-spritekit-scene-sks-files-necessary-in-my-project Tried to do something equivalent in Obj-C, but got no where.
Replies
1
Boosts
0
Views
710
Activity
Nov ’21
Sound effects in SpriteKit - memory and frame rate issues
I am working on my first game. I was using SKAction.playSoundFileNamed() to play .wav files in my assets, but this was causing problematic memory use growth. After looking online and reading that method has been linked to leaks, I switched to SKAudioNodes. I have added many of those to my scene, and they work, but the frame rate is lower now than before. Any suggestions? I had used this (but I had memory usage growing): let hiss = SKAction.playSoundFileNamed("hiss.wav", waitForCompletion: false) run(hiss) Now I have this (but frame rates are down): let hiss: SKAudioNode = SKAudioNode(fileNamed: "hiss.wav") hiss.autoplayLooped = false hiss.isPositional = false addChild(hiss) hiss.run(SKAction.play())  Any tips?
Replies
1
Boosts
0
Views
848
Activity
Nov ’21
SpriteKit draw calls not batched when using a texture atlas from data stored in the app bundle
It seems that SpriteKit doesn't batch the draw calls for textures in the same texture atlas. There are two different behaviors, based on how the SKTextureAtlas gets initialized: The draw calls are not batched when the texture atlas is initialized using SKTextureAtlas(named:) (loading the texture atlas from data stored in the app bundle). But the draw calls seem to be batched when the texture atlas is created dynamically using SKTextureAtlas(dictionary:). The following images show the two different behaviors and the SpriteAtlas inside the Assets Catalog. 1. Draw calls not batched: 2. Draw calls batched: The SpriteAtlas: I created a sample Xcode 13 project to show the different behavior: https://github.com/clns/spritekit-atlas-batching. I have tried this on the iOS 15 simulator on macOS Big Sur 11.6.1. The code to reproduce is very simple: import SpriteKit class GameScene: SKScene { override func didMove(to view: SKView) { let atlas = SKTextureAtlas(named: "Sprites") // let atlas = SKTextureAtlas(dictionary: ["costume": UIImage(named: "costume")!, "tank": UIImage(named: "tank")!]) let costume = SKSpriteNode(texture: atlas.textureNamed("costume")) costume.setScale(0.3) costume.position = CGPoint(x: 200, y: 650) let tank = SKSpriteNode(texture: atlas.textureNamed("tank")) tank.setScale(0.3) tank.position = CGPoint(x: 500, y: 650) addChild(costume) addChild(tank) } } Am I missing something?
Replies
1
Boosts
0
Views
1.4k
Activity
Nov ’21
Rendering issues (objects blurred, frame dimensions = 1) when SKScene is inside SwiftUI context
I am developing an app that contains a SpriteKit scene embedded inside a SwiftUI context.I am trying to render a simple SKShapeNode like this:import Foundation import SpriteKit class UIConnection: SKShapeNode { override init() { super.init() self.fillColor = UIColor.clear self.strokeColor = UIColor.blue self.lineWidth = 0.01 } func updatePositions(node1 : CGPoint, node2 : CGPoint) { let path = CGMutablePath() path.move(to: node1) path.addLine(to: CGPoint(x: node1.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node1.y)) path.addLine(to: node1) self.path = path } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } }When I am adding that Node inside the standard SpriteKit game project template in XCode (without any SwiftUI things), everything is working fine, I get a non-filled rectangle with a blue outline. The frame.width and frame.height variables are valid pixel dimensions like 750 x 1334.let node = UIConnection() self.addChild(node) node.updatePositions(node1: CGPoint(x: frame.midX-frame.width/4, y: frame.midY-frame.height/4), node2: CGPoint(x: frame.midX+frame.width/4, y: frame.midY+frame.height/4))Now I want to embed the SKScene inside a SwiftUI context using this approach:https://dev.to/sgchipman/using-spritekit-with-swiftui-ibcFirst thing I encounter is the fact that frame.width and frame.height both result in a value of 1.Adding the above node to the embedded SKScene results in an extremely blurred rectangle, so no solid line but some weird cloudy object.
Replies
1
Boosts
0
Views
1.1k
Activity
Nov ’21