SpriteKit

RSS for tag

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

Posts under SpriteKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

crash 1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width
just using SKView func texture(from node: SKNode, crop: CGRect) -> SKTexture? crash_info_entry_0 -[MTLTextureDescriptorInternal validateWithDevice:]:1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (8256) greater than the maximum allowed size of 8192. MTLTextureDescriptor has height (8242) greater than the maximum allowed size of 8192. ' Help!
0
0
820
Aug ’23
Sorting of isometric SKTileMapNode incorrect?
Im programmatically using SKTileMapNode. The code is C# (Xamarin.iOS) but should be readable by every Swift/ObjC developer.The problem is that the sorting of tiles in isometric projection seems to be incorrect and I cannot see why. To test, the map has 1 row and 5 columns. See the screenshot:https://dl.dropboxusercontent.com/u/111612273/SVhjD.pngThe tiles at 0|0 and 2|0 are in front of the others. The pyramid styled tile at 4|0 however, is drawn correctly in front of the one at 3|0.I'm using two simple tiles: The first one has a resolution of 133x83px and the second one is 132x131px:https://dl.dropboxusercontent.com/u/111612273/bcIvP.pngandhttps://dl.dropboxusercontent.com/u/111612273/wzCZV.pngThis is what it looks like in Tiled and what I am trying to reproduce: https://dl.dropboxusercontent.com/u/111612273/66G6p.pngThe tile map is setup and added to the scene using the following code:var tileDef1 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_014")); var tileDef2 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_036")); var tileGroup1 = new SKTileGroup (tileDef1); var tileGroup2 = new SKTileGroup (tileDef2); var tileSet = new SKTileSet (new [] { tileGroup1, tileGroup2 }, SKTileSetType.Isometric); var tileMap = SKTileMapNode.Create(tileSet, 5, 2, new CGSize (128, 64)); tileMap.Position = new CGPoint (0, 0); tileMap.SetTileGroup (tileGroup1, 0, 0); tileMap.SetTileGroup (tileGroup2, 1, 0); tileMap.SetTileGroup (tileGroup1, 2, 0); tileMap.SetTileGroup (tileGroup2, 3, 0); tileMap.SetTileGroup (tileGroup2, 4, 0); tileMap.AnchorPoint = new CGPoint (0, 0); Add (tileMap);The tile size used to initialise the tile map (128|64) looks strange to me. It really hasn't anything to do with the texture size of the tiles and unlike everywhere else in SpriteKit it doesn't seem to be using "points". However, this is the size where Tiled is giving me nicely aligned tiles and also SpriteKit is looking good, besides the sorting issue.What am I doing wrong or where am I thinking wrong?
7
0
2.1k
Jul ’23
i fail with isJumping = true for my mobile game
hey i want my character to add a jumping animation to my doodlejump clone style. I think I know how to specify the sprites but I fail with the query isJumping = true. can someone help me? the coin provides the platform on which the player lands the ground is only at the start // GameScene.swift // megaJump // // Created by Dennis Sergel on 26.06.23. // import Foundation import SpriteKit class GameScene: SKScene, SKPhysicsContactDelegate{ let background = SKSpriteNode(imageNamed: "background") let player = SKSpriteNode(imageNamed: "Monster2") let ground = SKSpriteNode(imageNamed: "ground") let coin = SKSpriteNode(imageNamed: "coin") enum bitmasks: UInt32 { case player = 0b1 case coin = 0b10 } override func didMove(to view: SKView) { self.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) self.anchorPoint = .zero background.position = CGPoint(x: size.width / 2, y: 1060) background.zPosition = 1 background.setScale(1.3) addChild(background) physicsWorld.contactDelegate = self ground.position = CGPoint(x: size.width / 2, y: 80) ground.zPosition = 5 ground.setScale(2.5) ground.physicsBody = SKPhysicsBody(rectangleOf: ground.size) ground.physicsBody?.isDynamic = false ground.physicsBody?.affectedByGravity = false addChild(ground) player.position = CGPoint(x: size.width / 2, y: 150) player.zPosition = 80 player.setScale(0.14) player.physicsBody = SKPhysicsBody(circleOfRadius: player.size.height / 2) player.physicsBody?.isDynamic = false // later is true player.physicsBody?.restitution = 1 player.physicsBody?.friction = 0 player.physicsBody?.angularDamping = 0 player.physicsBody?.categoryBitMask = bitmasks.player.rawValue player.physicsBody?.collisionBitMask = 0 player.physicsBody?.contactTestBitMask = bitmasks.coin.rawValue addChild(player) animatePlayer(isJumping: true) makeCoin() } func animatePlayer (isJumping: Bool){ if isJumping { player.texture = SKTexture(imageNamed: "monster") }else{ player.texture = SKTexture(imageNamed: "Monster2") } } func didBegin(_ contact: SKPhysicsContact) { let contactA: SKPhysicsBody let contactB: SKPhysicsBody if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask{ contactA = contact.bodyA // player contactB = contact.bodyB // Coin } else { contactA = contact.bodyB // player contactB = contact.bodyA // coin } if contactA.categoryBitMask == bitmasks.player.rawValue && contactB.categoryBitMask == bitmasks.coin.rawValue{ if player.physicsBody!.velocity.dy < 0 { player.physicsBody?.velocity = CGVector(dx: player.physicsBody!.velocity.dx, dy: 120) } } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) player.position.x = location.x } } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { player.physicsBody?.isDynamic = true player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 120)) } func makeCoin() { coin.position = CGPoint(x: size.width / 2, y: 150) coin.zPosition = 5 coin.setScale(0.14) coin.physicsBody = SKPhysicsBody(rectangleOf: coin.size) coin.physicsBody?.isDynamic = false coin.physicsBody?.allowsRotation = false coin.physicsBody?.affectedByGravity = false coin.physicsBody?.categoryBitMask = bitmasks.coin.rawValue coin.physicsBody?.collisionBitMask = 0 coin.physicsBody?.contactTestBitMask = bitmasks.player.rawValue addChild(coin) } }
3
0
1.3k
Jun ’23
Adding Component to Sprite in SpriteKit/ GameplayKit grey out simulator after launch screen
I have Xcode 14.3.1 /////START of Code import SpriteKit import GameplayKit class PlayerControlComponent : GKComponent, ControlInputDelegate { var touchControlNode : TouchControlInputNode? func setupControls (camera: SKCameraNode, scene: SKScene){ touchControlNode = TouchControlInputNode(frame: scene.frame) touchControlNode?.inputDelegate = self touchControlNode?.position = CGPoint.zero camera.addChild(touchControlNode!) } func follow(command: String?) { print("command:(String(describing: command))") } } ///////End of code I have no error in project and the simulator shows launch screen then precedes to what I have on the game scene when I have no component in the component inspector of the the Sprite(player) when I add a component to the component inspector of the Sprite(player) that is when, after the launch screen, it is a grey screen. The component is supposed to add the controls I created in the TouchContorolNode file and have the camera and controls so as the player moves the controls follow the Sprite(player). Does anyone know why the screen is turning Grey after the launch screen with the comment attached to the Sprite(player)?
1
0
1.1k
Jun ’23
Issue with Path shape
Hey y'all, I've been facing an incredibly bothersome error and wanted to see if you had any comments/fixes for whats going on. I'm attempting to create a custom shape using the Path { path in } initalizer, but am receiving the following error Referencing initializer 'init(codingKey:)' on 'RawRepresentable' requires that 'Path' conform to 'CodingKeyRepresentable' I ended up copying the code here, but am still receiving the same errors. I'm running xCode 14.3
1
0
775
Jun ’23
Help need SpriteKit player not affected by gravity but still able to jump and kick and walk but only to a vertían point
move sprite in SpriteKit along x and y but within a playable area so they do it walk on the “houses” but still jump which would have them overlap the house since this is 2D game any advice? I have tried playable rect but I get the fatal error and not sure how to set up the vectoring so the player can still jump and kick even whne not affected by gravit.
0
0
621
Jun ’23
XCode can't find SpriteKit?
This seems to be a pretty weird issue. I'm following along with a SpriteKit tutorial, and while I can build my project and run it on my phone, I keep getting this error in the IDE: Cannot load underlying module for SpriteKit It says it cannot load the module but that's weird because SpriteKit should be a native framework that must've been installed with my XCode. It is pretty annoying because XCode is not context-aware, and code completion doesn't work for any object that's derived from SpriteKit. Here's my system info: XCode version: Version 12.0 (12A7209) MacOS version: MacOS Catalina 10.15.7 (19H2) Is this a bug in XCode?
3
0
2.6k
Jun ’23
Is there a way to save SKTextureAtlas(dictionary) sprite sheets to disk to read later?
My app uses SpriteKit and requires the use of SKTextureAtlas for performance. However, it uses user-generated content, which means that atlases don’t initialize using bundled images, but instead have to recreate all sprite sheets, leading to long loading times. Is it possible to save the sprite sheets made from user-generated content to disk so that SKTextureAtlas can load them instead of recreating all sprite sheets upon every initialization? Is there any alternative solution to this problem? For example, is there a way to dump a bunch of images into memory to use as a texture pool and keep them there until deallocated?
0
0
776
May ’23
New onset Metal Validation failure
I have an older App using SpriteKit and have updated to Xcode 14.3. Compilation and linking is ok. App never gets to my code but crashes in AppDelegate with: Metal API Validation Enabled -[MTLDebugDevice newLibraryWithURL:error:]:2250: failed assertion `url must not be nil.' I do not anywhere explicitly init() or call Metal. Using LLDB at the point of crash, I tried to peek into the App Bundle but po Bundle.main.paths(forResourcesOfType: "URL", inDirectory: "nil") 0 elements likewise: po Bundle.main.paths(forResourcesOfType: "*", inDirectory: "nil") 0 elements I suspect a build script or preformed bundle.main got screwed up, but I do not know how to investigate. I should that this seems to be isolated to one MacBook Pro, compiles and runs fine on an iMac! Any thoughts?
3
0
2.1k
May ’23
Safe to update SKSpriteNode's texture on background thread?
I understand UI updates have to be on the main thread, but what about SKSpriteNode's texture? Can I update that in the background? I can update it in the background and it works like I want it to. No crashes, warnings, etc. I did verify that the thread is not the main thread via [NSThread isMainThread]. I have since wrapped the texture change in a dispatch_sync on the main queue and it works the same as without it. Regards, Patrick
0
0
950
May ’23
Drawing a UIImageView behind SpriteKit Scene
I am working on a simple SpriteKit App which has a sprite based game which I would like to superimpose on a complex UIImageView ( > 100 subviews) and which I will need to access during game play (ie change alpha of subviews and other animations) I have tried to get this effect a number of ways but none work. First I tried to make the background a Node filled with substrates, but the subsprites do not position correctly. The most promising approach so far is to combine the views of the main ViewController and the Scene: √ 1) Desired background UIImageView ("bg") is placed in view of main ViewController and draw into it √ 2) Create a Protocol with delegate methods that can be called from the game's GameScene.swift √ 3) Create Scene in main VC in the usual way. Set the scene background color to .Clear √ 4) in GameScene.swift set up the reference to the protocol delegate √ 5) prove I have access to the bg image from didMove(to view: SKView) by changing alpha or background color. Delegate access from didBegin(contact) also works The problem is: that my bg imageView is drawn IN FRONT OF my game scene and I can not figure out how to change the draw order. The game scene is not in the subviews array of the mainVC, and the bg image view is not in the subViews of the game scene view. Without common references, I do not see how to modify the view hierarchy. Does anyone have a way to draw the bg image behind the mostly transparent game scene?
0
0
778
Apr ’23
Possible to batch SKEmitterNodes?
I've noticed that every SKEmitterNode added to a scene increased the draw call count. Even if the emitter node is used the same texture from a texture atlas. Is there a method for batching mutliple emitter nodes that use the same texture? The use case is that I am attaching an emitter node to bullets.
1
2
1.2k
Apr ’23
SpriteKit fillTexture different results in TestFlight
I have a screen in an app that uses SpriteKit to display items that should look kind of like bubbles. When I'm testing it with the simulator or my real device everything looks fine. However when I install the app through TestFlight the appearance is very different. This is how it should look and it is running directly from Xcode: and this is the installed app: I'm using a semi-transparent png image to achieve the 3D look. Here is the debug view hierarchy: So it's a SKShapeNode with a SKTexture added as a child of the main node. It appears also that the View Hierarchy looks similar to the TestFlight one but I guess I shouldn't rely on that as it's not a real rendering the way it's on a device. I tried to change blending which completely changes the look and the results are again different locally and installed. Tried changing the rendering mode as well but it's still the same. Any idea why it looks different and how can I know which appearance it will be when released on the App Store?
0
0
847
Mar ’23
Broken Images when distributing apps through TestFlight
When testing my game on Xcode and building to an iOS or iPad device all images in the game show. Yet when I submit the app to TestFlight, some devices are not showing all of the assets, replacing the missing images with a red x in a white box. It seems to be tied to certain atlas maps. For example both player 1 and player 2 have their own separate atlas maps. On an iPhone XR both player 1 and 2 are missing showing the red x box. Yet on another device such as an iPad mini for example only player 2 assets are missing. It seems strange that Xcode would be distributing some assets to one device and none to others. What would cause this strange behavior and how to fix it? Thanks in advance.
2
0
1.4k
Feb ’23
How to hide the scroll bar in a SpriteView when Digital Crown is used
I am updating my Watch games to use SwiftUI and am using a SpriteView to render my SpriteKit SKScene. However, my games now show the scroll bar at the top right of the Watch screen when I turn the Digital Crown. This didn't happen in the old version. Is there a way to hide the scroll bar? I see that ScrollView has a showsIndicators option to turn off the scroll bar, but I can't find this for SpriteView. Does anyone have a workaround to remove the scroll bar? This is the code I am currently using to show my GameScene.   @State private var crownPosition = 0.0   var body: some View {         GeometryReader { reader in       SpriteView(scene: GameScene(size: reader.size, crownPosition: $crownPosition))         .focusable()         .digitalCrownRotation($crownPosition)     }   } Thanks!
2
0
3.3k
Feb ’23
Problem: OSX + SwiftUI + SpriteKit + DragGesture
I am using Xcode 14.2 and running on Ventura 13.2. There is no problem working with iOS or the OSX playground. But there is a problem having it work with OSX. The first problem is that the DragGesture is not recognized on OSX: nothing happens on a drag of an SKNode. The second problem (using a kludge by putting a "glass pane" in front of the spriteView) is that the dragging now works, but the coordinate system is flipped. Here is the code: import SwiftUI import SpriteKit @main struct TestOnMacApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } struct ContentView: View {     @State private var gameScene = GameScene()     let glassPaneColor =         CGColor(red: 0, green: 0, blue: 0, alpha: 0.01)     var body: some View {         ZStack {             SpriteView(scene: gameScene) // Comment out the following line: drag won't work             Color(cgColor: glassPaneColor)         }         .gesture(DragGesture(minimumDistance: 0)             .onChanged { gesture in                 let location = gesture.location                 let sceneLocation =                     gameScene.convertPoint(fromView: location)                 gameScene.spriteNode.position = sceneLocation             })     } } class GameScene: SKScene {     let sceneSize = CGSize(width: 500, height: 500)     let nodeSize = CGSize(width: 50, height: 50)     let spriteNode: SKSpriteNode     required init?(coder aDecoder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }     override init() {         spriteNode = SKSpriteNode(texture: nil, size: nodeSize)         super.init(size: sceneSize)         scaleMode = .resizeFill         backgroundColor = .white         spriteNode.name = "spriteNode"         spriteNode.color = .blue         spriteNode.position = CGPoint(x: 100, y: 100)         addChild(spriteNode)     } }
0
0
865
Jan ’23
SKTileSet tiles are blurry
I have a folder containing many 8x8 tile images. They are png images and are for sure 8x8 pixels. I added the folder of tile images to the Assets.xcassets in Xcode. I have also added a .sks tileset to my Xcode project. When I add one of the images to my tile set in a new tilegroup the image is very blurry. It still is when put on a SKTileMapNode in the scene editor. It worked perfectly fine just yesterday and I have no idea what changed since I left Xcode open and haven't changed anything since then. I have tried many things. Here is a list to rule out possible reasons for this issue: The TileSet and the SKTileMapNode tileSize property is the correct 8x8 The size of the SKTileMapNode and the actual window itself are both the same aspect ratio of 2:1 w:h and the scale mode is set to .aspect fit. I have tried cleaning the project with Xcode and restarting Xcode. I have tried making a new TileSet I have tried making a new SKTileMapNode I have tried re-importing the tile images folder I have tried changing properties in the actual tile images themselves in the .xcassets I have tried toggling Enable Automapping in the SKTileMapNode I have tried making a completely new project with just the tileset and tilemapnode Through my testing the issue seems to be with adding the tiles to the tileset. For some reason they are always blurry and I have no idea why. There is only one other post about this that I could find which was on StackOverflow with no answers and one reply saying maybe the tiles are being resized. ChatGPT gave a list of possible solutions which sometimes has helped with other problems but none of those worked either. I am on Xcode version 14.2
2
0
838
Jan ’23
crash 1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width
just using SKView func texture(from node: SKNode, crop: CGRect) -> SKTexture? crash_info_entry_0 -[MTLTextureDescriptorInternal validateWithDevice:]:1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (8256) greater than the maximum allowed size of 8192. MTLTextureDescriptor has height (8242) greater than the maximum allowed size of 8192. ' Help!
Replies
0
Boosts
0
Views
820
Activity
Aug ’23
Sorting of isometric SKTileMapNode incorrect?
Im programmatically using SKTileMapNode. The code is C# (Xamarin.iOS) but should be readable by every Swift/ObjC developer.The problem is that the sorting of tiles in isometric projection seems to be incorrect and I cannot see why. To test, the map has 1 row and 5 columns. See the screenshot:https://dl.dropboxusercontent.com/u/111612273/SVhjD.pngThe tiles at 0|0 and 2|0 are in front of the others. The pyramid styled tile at 4|0 however, is drawn correctly in front of the one at 3|0.I'm using two simple tiles: The first one has a resolution of 133x83px and the second one is 132x131px:https://dl.dropboxusercontent.com/u/111612273/bcIvP.pngandhttps://dl.dropboxusercontent.com/u/111612273/wzCZV.pngThis is what it looks like in Tiled and what I am trying to reproduce: https://dl.dropboxusercontent.com/u/111612273/66G6p.pngThe tile map is setup and added to the scene using the following code:var tileDef1 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_014")); var tileDef2 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_036")); var tileGroup1 = new SKTileGroup (tileDef1); var tileGroup2 = new SKTileGroup (tileDef2); var tileSet = new SKTileSet (new [] { tileGroup1, tileGroup2 }, SKTileSetType.Isometric); var tileMap = SKTileMapNode.Create(tileSet, 5, 2, new CGSize (128, 64)); tileMap.Position = new CGPoint (0, 0); tileMap.SetTileGroup (tileGroup1, 0, 0); tileMap.SetTileGroup (tileGroup2, 1, 0); tileMap.SetTileGroup (tileGroup1, 2, 0); tileMap.SetTileGroup (tileGroup2, 3, 0); tileMap.SetTileGroup (tileGroup2, 4, 0); tileMap.AnchorPoint = new CGPoint (0, 0); Add (tileMap);The tile size used to initialise the tile map (128|64) looks strange to me. It really hasn't anything to do with the texture size of the tiles and unlike everywhere else in SpriteKit it doesn't seem to be using "points". However, this is the size where Tiled is giving me nicely aligned tiles and also SpriteKit is looking good, besides the sorting issue.What am I doing wrong or where am I thinking wrong?
Replies
7
Boosts
0
Views
2.1k
Activity
Jul ’23
No audio on local device build
I built a simple Swift game in SpriteKit. I have audio on the simulator but no audio or sound effects on the device. Any suggestions?
Replies
3
Boosts
0
Views
2.9k
Activity
Jul ’23
i fail with isJumping = true for my mobile game
hey i want my character to add a jumping animation to my doodlejump clone style. I think I know how to specify the sprites but I fail with the query isJumping = true. can someone help me? the coin provides the platform on which the player lands the ground is only at the start // GameScene.swift // megaJump // // Created by Dennis Sergel on 26.06.23. // import Foundation import SpriteKit class GameScene: SKScene, SKPhysicsContactDelegate{ let background = SKSpriteNode(imageNamed: "background") let player = SKSpriteNode(imageNamed: "Monster2") let ground = SKSpriteNode(imageNamed: "ground") let coin = SKSpriteNode(imageNamed: "coin") enum bitmasks: UInt32 { case player = 0b1 case coin = 0b10 } override func didMove(to view: SKView) { self.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) self.anchorPoint = .zero background.position = CGPoint(x: size.width / 2, y: 1060) background.zPosition = 1 background.setScale(1.3) addChild(background) physicsWorld.contactDelegate = self ground.position = CGPoint(x: size.width / 2, y: 80) ground.zPosition = 5 ground.setScale(2.5) ground.physicsBody = SKPhysicsBody(rectangleOf: ground.size) ground.physicsBody?.isDynamic = false ground.physicsBody?.affectedByGravity = false addChild(ground) player.position = CGPoint(x: size.width / 2, y: 150) player.zPosition = 80 player.setScale(0.14) player.physicsBody = SKPhysicsBody(circleOfRadius: player.size.height / 2) player.physicsBody?.isDynamic = false // later is true player.physicsBody?.restitution = 1 player.physicsBody?.friction = 0 player.physicsBody?.angularDamping = 0 player.physicsBody?.categoryBitMask = bitmasks.player.rawValue player.physicsBody?.collisionBitMask = 0 player.physicsBody?.contactTestBitMask = bitmasks.coin.rawValue addChild(player) animatePlayer(isJumping: true) makeCoin() } func animatePlayer (isJumping: Bool){ if isJumping { player.texture = SKTexture(imageNamed: "monster") }else{ player.texture = SKTexture(imageNamed: "Monster2") } } func didBegin(_ contact: SKPhysicsContact) { let contactA: SKPhysicsBody let contactB: SKPhysicsBody if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask{ contactA = contact.bodyA // player contactB = contact.bodyB // Coin } else { contactA = contact.bodyB // player contactB = contact.bodyA // coin } if contactA.categoryBitMask == bitmasks.player.rawValue && contactB.categoryBitMask == bitmasks.coin.rawValue{ if player.physicsBody!.velocity.dy < 0 { player.physicsBody?.velocity = CGVector(dx: player.physicsBody!.velocity.dx, dy: 120) } } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) player.position.x = location.x } } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { player.physicsBody?.isDynamic = true player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 120)) } func makeCoin() { coin.position = CGPoint(x: size.width / 2, y: 150) coin.zPosition = 5 coin.setScale(0.14) coin.physicsBody = SKPhysicsBody(rectangleOf: coin.size) coin.physicsBody?.isDynamic = false coin.physicsBody?.allowsRotation = false coin.physicsBody?.affectedByGravity = false coin.physicsBody?.categoryBitMask = bitmasks.coin.rawValue coin.physicsBody?.collisionBitMask = 0 coin.physicsBody?.contactTestBitMask = bitmasks.player.rawValue addChild(coin) } }
Replies
3
Boosts
0
Views
1.3k
Activity
Jun ’23
Adding Component to Sprite in SpriteKit/ GameplayKit grey out simulator after launch screen
I have Xcode 14.3.1 /////START of Code import SpriteKit import GameplayKit class PlayerControlComponent : GKComponent, ControlInputDelegate { var touchControlNode : TouchControlInputNode? func setupControls (camera: SKCameraNode, scene: SKScene){ touchControlNode = TouchControlInputNode(frame: scene.frame) touchControlNode?.inputDelegate = self touchControlNode?.position = CGPoint.zero camera.addChild(touchControlNode!) } func follow(command: String?) { print("command:(String(describing: command))") } } ///////End of code I have no error in project and the simulator shows launch screen then precedes to what I have on the game scene when I have no component in the component inspector of the the Sprite(player) when I add a component to the component inspector of the Sprite(player) that is when, after the launch screen, it is a grey screen. The component is supposed to add the controls I created in the TouchContorolNode file and have the camera and controls so as the player moves the controls follow the Sprite(player). Does anyone know why the screen is turning Grey after the launch screen with the comment attached to the Sprite(player)?
Replies
1
Boosts
0
Views
1.1k
Activity
Jun ’23
Issue with Path shape
Hey y'all, I've been facing an incredibly bothersome error and wanted to see if you had any comments/fixes for whats going on. I'm attempting to create a custom shape using the Path { path in } initalizer, but am receiving the following error Referencing initializer 'init(codingKey:)' on 'RawRepresentable' requires that 'Path' conform to 'CodingKeyRepresentable' I ended up copying the code here, but am still receiving the same errors. I'm running xCode 14.3
Replies
1
Boosts
0
Views
775
Activity
Jun ’23
Help need SpriteKit player not affected by gravity but still able to jump and kick and walk but only to a vertían point
move sprite in SpriteKit along x and y but within a playable area so they do it walk on the “houses” but still jump which would have them overlap the house since this is 2D game any advice? I have tried playable rect but I get the fatal error and not sure how to set up the vectoring so the player can still jump and kick even whne not affected by gravit.
Replies
0
Boosts
0
Views
621
Activity
Jun ’23
XCode can't find SpriteKit?
This seems to be a pretty weird issue. I'm following along with a SpriteKit tutorial, and while I can build my project and run it on my phone, I keep getting this error in the IDE: Cannot load underlying module for SpriteKit It says it cannot load the module but that's weird because SpriteKit should be a native framework that must've been installed with my XCode. It is pretty annoying because XCode is not context-aware, and code completion doesn't work for any object that's derived from SpriteKit. Here's my system info: XCode version: Version 12.0 (12A7209) MacOS version: MacOS Catalina 10.15.7 (19H2) Is this a bug in XCode?
Replies
3
Boosts
0
Views
2.6k
Activity
Jun ’23
Is there a way to save SKTextureAtlas(dictionary) sprite sheets to disk to read later?
My app uses SpriteKit and requires the use of SKTextureAtlas for performance. However, it uses user-generated content, which means that atlases don’t initialize using bundled images, but instead have to recreate all sprite sheets, leading to long loading times. Is it possible to save the sprite sheets made from user-generated content to disk so that SKTextureAtlas can load them instead of recreating all sprite sheets upon every initialization? Is there any alternative solution to this problem? For example, is there a way to dump a bunch of images into memory to use as a texture pool and keep them there until deallocated?
Replies
0
Boosts
0
Views
776
Activity
May ’23
New onset Metal Validation failure
I have an older App using SpriteKit and have updated to Xcode 14.3. Compilation and linking is ok. App never gets to my code but crashes in AppDelegate with: Metal API Validation Enabled -[MTLDebugDevice newLibraryWithURL:error:]:2250: failed assertion `url must not be nil.' I do not anywhere explicitly init() or call Metal. Using LLDB at the point of crash, I tried to peek into the App Bundle but po Bundle.main.paths(forResourcesOfType: "URL", inDirectory: "nil") 0 elements likewise: po Bundle.main.paths(forResourcesOfType: "*", inDirectory: "nil") 0 elements I suspect a build script or preformed bundle.main got screwed up, but I do not know how to investigate. I should that this seems to be isolated to one MacBook Pro, compiles and runs fine on an iMac! Any thoughts?
Replies
3
Boosts
0
Views
2.1k
Activity
May ’23
Safe to update SKSpriteNode's texture on background thread?
I understand UI updates have to be on the main thread, but what about SKSpriteNode's texture? Can I update that in the background? I can update it in the background and it works like I want it to. No crashes, warnings, etc. I did verify that the thread is not the main thread via [NSThread isMainThread]. I have since wrapped the texture change in a dispatch_sync on the main queue and it works the same as without it. Regards, Patrick
Replies
0
Boosts
0
Views
950
Activity
May ’23
Drawing a UIImageView behind SpriteKit Scene
I am working on a simple SpriteKit App which has a sprite based game which I would like to superimpose on a complex UIImageView ( > 100 subviews) and which I will need to access during game play (ie change alpha of subviews and other animations) I have tried to get this effect a number of ways but none work. First I tried to make the background a Node filled with substrates, but the subsprites do not position correctly. The most promising approach so far is to combine the views of the main ViewController and the Scene: √ 1) Desired background UIImageView ("bg") is placed in view of main ViewController and draw into it √ 2) Create a Protocol with delegate methods that can be called from the game's GameScene.swift √ 3) Create Scene in main VC in the usual way. Set the scene background color to .Clear √ 4) in GameScene.swift set up the reference to the protocol delegate √ 5) prove I have access to the bg image from didMove(to view: SKView) by changing alpha or background color. Delegate access from didBegin(contact) also works The problem is: that my bg imageView is drawn IN FRONT OF my game scene and I can not figure out how to change the draw order. The game scene is not in the subviews array of the mainVC, and the bg image view is not in the subViews of the game scene view. Without common references, I do not see how to modify the view hierarchy. Does anyone have a way to draw the bg image behind the mostly transparent game scene?
Replies
0
Boosts
0
Views
778
Activity
Apr ’23
Possible to batch SKEmitterNodes?
I've noticed that every SKEmitterNode added to a scene increased the draw call count. Even if the emitter node is used the same texture from a texture atlas. Is there a method for batching mutliple emitter nodes that use the same texture? The use case is that I am attaching an emitter node to bullets.
Replies
1
Boosts
2
Views
1.2k
Activity
Apr ’23
SpriteKit fillTexture different results in TestFlight
I have a screen in an app that uses SpriteKit to display items that should look kind of like bubbles. When I'm testing it with the simulator or my real device everything looks fine. However when I install the app through TestFlight the appearance is very different. This is how it should look and it is running directly from Xcode: and this is the installed app: I'm using a semi-transparent png image to achieve the 3D look. Here is the debug view hierarchy: So it's a SKShapeNode with a SKTexture added as a child of the main node. It appears also that the View Hierarchy looks similar to the TestFlight one but I guess I shouldn't rely on that as it's not a real rendering the way it's on a device. I tried to change blending which completely changes the look and the results are again different locally and installed. Tried changing the rendering mode as well but it's still the same. Any idea why it looks different and how can I know which appearance it will be when released on the App Store?
Replies
0
Boosts
0
Views
847
Activity
Mar ’23
GCVirtualController X and Y Position
hey hey i have a question and i use the GCVirtualController in a spritekit game. But I think the elements in my scene are way too high. I would like them below. is it possible to change the elements such as the thumbstick, the Y or X position?
Replies
2
Boosts
0
Views
1.5k
Activity
Mar ’23
Swarm simulation
I'm new to iOS. What would be the right toolkit to create something like a swarm animation with thousands of objects on the screen moving at high speed?
Replies
2
Boosts
1
Views
1.8k
Activity
Mar ’23
Broken Images when distributing apps through TestFlight
When testing my game on Xcode and building to an iOS or iPad device all images in the game show. Yet when I submit the app to TestFlight, some devices are not showing all of the assets, replacing the missing images with a red x in a white box. It seems to be tied to certain atlas maps. For example both player 1 and player 2 have their own separate atlas maps. On an iPhone XR both player 1 and 2 are missing showing the red x box. Yet on another device such as an iPad mini for example only player 2 assets are missing. It seems strange that Xcode would be distributing some assets to one device and none to others. What would cause this strange behavior and how to fix it? Thanks in advance.
Replies
2
Boosts
0
Views
1.4k
Activity
Feb ’23
How to hide the scroll bar in a SpriteView when Digital Crown is used
I am updating my Watch games to use SwiftUI and am using a SpriteView to render my SpriteKit SKScene. However, my games now show the scroll bar at the top right of the Watch screen when I turn the Digital Crown. This didn't happen in the old version. Is there a way to hide the scroll bar? I see that ScrollView has a showsIndicators option to turn off the scroll bar, but I can't find this for SpriteView. Does anyone have a workaround to remove the scroll bar? This is the code I am currently using to show my GameScene.   @State private var crownPosition = 0.0   var body: some View {         GeometryReader { reader in       SpriteView(scene: GameScene(size: reader.size, crownPosition: $crownPosition))         .focusable()         .digitalCrownRotation($crownPosition)     }   } Thanks!
Replies
2
Boosts
0
Views
3.3k
Activity
Feb ’23
Problem: OSX + SwiftUI + SpriteKit + DragGesture
I am using Xcode 14.2 and running on Ventura 13.2. There is no problem working with iOS or the OSX playground. But there is a problem having it work with OSX. The first problem is that the DragGesture is not recognized on OSX: nothing happens on a drag of an SKNode. The second problem (using a kludge by putting a "glass pane" in front of the spriteView) is that the dragging now works, but the coordinate system is flipped. Here is the code: import SwiftUI import SpriteKit @main struct TestOnMacApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } struct ContentView: View {     @State private var gameScene = GameScene()     let glassPaneColor =         CGColor(red: 0, green: 0, blue: 0, alpha: 0.01)     var body: some View {         ZStack {             SpriteView(scene: gameScene) // Comment out the following line: drag won't work             Color(cgColor: glassPaneColor)         }         .gesture(DragGesture(minimumDistance: 0)             .onChanged { gesture in                 let location = gesture.location                 let sceneLocation =                     gameScene.convertPoint(fromView: location)                 gameScene.spriteNode.position = sceneLocation             })     } } class GameScene: SKScene {     let sceneSize = CGSize(width: 500, height: 500)     let nodeSize = CGSize(width: 50, height: 50)     let spriteNode: SKSpriteNode     required init?(coder aDecoder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }     override init() {         spriteNode = SKSpriteNode(texture: nil, size: nodeSize)         super.init(size: sceneSize)         scaleMode = .resizeFill         backgroundColor = .white         spriteNode.name = "spriteNode"         spriteNode.color = .blue         spriteNode.position = CGPoint(x: 100, y: 100)         addChild(spriteNode)     } }
Replies
0
Boosts
0
Views
865
Activity
Jan ’23
SKTileSet tiles are blurry
I have a folder containing many 8x8 tile images. They are png images and are for sure 8x8 pixels. I added the folder of tile images to the Assets.xcassets in Xcode. I have also added a .sks tileset to my Xcode project. When I add one of the images to my tile set in a new tilegroup the image is very blurry. It still is when put on a SKTileMapNode in the scene editor. It worked perfectly fine just yesterday and I have no idea what changed since I left Xcode open and haven't changed anything since then. I have tried many things. Here is a list to rule out possible reasons for this issue: The TileSet and the SKTileMapNode tileSize property is the correct 8x8 The size of the SKTileMapNode and the actual window itself are both the same aspect ratio of 2:1 w:h and the scale mode is set to .aspect fit. I have tried cleaning the project with Xcode and restarting Xcode. I have tried making a new TileSet I have tried making a new SKTileMapNode I have tried re-importing the tile images folder I have tried changing properties in the actual tile images themselves in the .xcassets I have tried toggling Enable Automapping in the SKTileMapNode I have tried making a completely new project with just the tileset and tilemapnode Through my testing the issue seems to be with adding the tiles to the tileset. For some reason they are always blurry and I have no idea why. There is only one other post about this that I could find which was on StackOverflow with no answers and one reply saying maybe the tiles are being resized. ChatGPT gave a list of possible solutions which sometimes has helped with other problems but none of those worked either. I am on Xcode version 14.2
Replies
2
Boosts
0
Views
838
Activity
Jan ’23