SpriteKit

RSS for tag

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

SpriteKit Documentation

Posts under SpriteKit tag

49 Posts
Sort by:
Post not yet marked as solved
7 Replies
1.7k Views
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?
Posted
by
Post marked as solved
3 Replies
2k Views
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?
Posted
by
Post not yet marked as solved
6 Replies
3.1k Views
Hello! Bare with me here, as there is a lot to explain! I am working on implementing a Game Center high score leaderboard into my game. I have looked around for examples of how to properly implement this code, but have come up short on finding much material. Therefore, I have tried implementing it myself based off information I found on apples documentation. Long story short, I am getting success printed when I update my score, but no scores are actually being posted (or at-least no scores are showing up on the Game Center leaderboard when opened). Before I show the code, one thing I have questioned is the fact that this game is still in development. In AppStoreConnect, the status of the leaderboard is "Not Live". Does this affect scores being posted? Onto the code. I have created a GameCenter class which handles getting the leaderboards and posting scores to a specific leaderboard. I will post the code in whole, and will discuss below what is happening. PLEASE VIEW ATTACHED TEXT TO SEE THE GAMECENTER CLASS! GameCenter class - https://developer.apple.com/forums/content/attachment/0dd6dca8-8131-44c8-b928-77b3578bd970 In a different GameScene, once the game is over, I request to post a new high score to Game Center with this line of code: GameCenter.shared.submitScore(id: GameCenterLeaderboards.HighScore.rawValue) Now onto the logic of my code. For the longest time I struggled to figure out how to submit a score. I figured out that in Xcode 12, they deprecated a lot of functions that previously worked for me. Not is seems that we have to load all leaderboards (or the ones we want). That is the purpose behind the leaderboards private variable in the Game Center class. On the start up of the app, I call authenticate player. Once this callback is reached, I call loadLeaderboards which will load the leaderboards for each string id in an enum that I have elsewhere. Each of these leaderboards will be created as a Leaderboard object, and saved in the private leaderboard array. This is so I have access to these leaderboards later when I want to submit a score. Once the game is over, I am calling submitScore with the leaderboard id I want to post to. Right now, I only have a high score, but in the future I may add a parameter to this with the value so it works for other leaderboards as well. Therefore, no value is passed in since I am pulling from local storage which holds the high score. submitScore will get the leaderboard from the private leaderboard array that has the same id as the one passed in. Once I get the correct leaderboard, I submit a score to that leaderboard. Once the callback is hit, I receive the output "Successfully submitted score to leaderboard". This looks promising, except for the fact that no score is actually posted. At startup, I am calling updatePlayerHighScore, which is not complete - but for the purpose of my point, retrieves the high score of the player from the leaderboard and is printing it out to the console. It is printing out (0), meaning that no score was posted. The last thing I have questions about is the context when submitting a score. According to the documentation, this seems to just be metadata that GameCenter does not care about, but rather something the developer can use. Therefore, I think I can cross this off as causing the problem. I believe I implemented this correctly, but for some reason, nothing is posting to the leaderboard. This was ALOT, but I wanted to make sure I got all my thoughts down. Any help on why this is NOT posting would be awesome! Thanks so much! Mark
Posted
by
Post not yet marked as solved
2 Replies
1.4k Views
GCVirtualController isn't displaying when used with SKScene class. The Virtual controllers appear but then it seems that they are obscured by the SKScene itself!? The documentation says that calling connect() will display the virtual controllers but I seem to be missing how to add the controllers to the SKScene? class GameScene: SKScene { private var _virtualController: Any? @available(iOS 15.0, *) public var virtualController: GCVirtualController? { get { return self._virtualController as? GCVirtualController } set { self._virtualController = newValue } } override func didMove(to view: SKView) { let background = SKSpriteNode(imageNamed: ".jpg") background.zPosition = -1 addChild(background) let virtualConfig = GCVirtualController.Configuration() virtualConfig.elements = [GCInputLeftThumbstick, GCInputRightThumbstick, GCInputButtonA, GCInputButtonB] virtualController = GCVirtualController(configuration: virtualConfig) virtualController?.connect() } } I've also tried adding the virtual controllers in the UIViewController but this doesn't work either.
Posted
by
Post not yet marked as solved
17 Replies
7.1k Views
I've an app I've been working on for quite some time now. It uses SpriteKit. The windows with the scenes in them are generated programmatically. All of a sudden, when it's up and running through XCode, the console throws out a continuous stream of errors - probably in the order of 1 per second. The main one that makes up this stream is: 2022-03-07 20:07:38.765930+0000 My*App[8461:465673] [] CurrentVBLDelta returned 0 for display 1 -- ignoring unreasonable value But others that appear slightly less frequently are: 2022-03-07 20:07:38.447800+0000 My*App[8461:465143] Metal GPU Frame Capture Enabled 2022-03-07 20:07:38.448070+0000 My*App[8461:465143] Metal API Validation Enabled 2022-03-07 20:07:38.613097+0000 My*App[8461:465640] [] [0x7f9596053820] CVCGDisplayLink::setCurrentDisplay: 1 2022-03-07 20:07:38.613415+0000 My*App[8461:465640] [] [0x7f9596053820] Bad CurrentVBLDelta for display 1 is zero. defaulting to 60Hz. 2022-03-07 20:07:38.613442+0000 My*App[8461:465640] [] [0x7f9596053800] CVDisplayLinkCreateWithCGDisplays count: 1 [displayID[0]: 0x1] [CVCGDisplayLink: 0x7f9596053820] 2022-03-07 20:07:38.613467+0000 My*App[8461:465640] [] [0x7f9596053800] CVDisplayLinkStart 2022-03-07 20:07:38.613487+0000 My*App[8461:465640] [] [0x7f9596053820] CVDisplayLink::start 2022-03-07 20:07:38.613541+0000 My*App[8461:465640] [] [0x7f9596053800] CVDisplayLinkStart 2022-03-07 20:07:38.613575+0000 My*App[8461:465640] [] [0x7f9596053820] CVDisplayLink::start 2022-03-07 20:07:38.613634+0000 My*App[8461:465671] [] [0x600000c09f10] CVXTime::reset 2022-03-07 20:07:38.613718+0000 My*App[8461:465671] [] CurrentVBLDelta returned 0 for display 1 -- ignoring unreasonable value 2022-03-07 20:07:38.639810+0000 My*App[8461:465671] [] CurrentVBLDelta returned 0 for display 1 -- ignoring unreasonable value 2022-03-07 20:07:38.639887+0000 My*App[8461:465671] [] [0x7f9596053820] CVCGDisplayLink::getDisplayTimes display: 1 -- SLSDisplayGetCurrentVBLDelta returned 0 => generating fake times 2022-03-07 20:07:38.673702+0000 My*App[8461:465653] [] [0x7f9596053820] CVCGDisplayLink::setCurrentDisplay: 1 2022-03-07 20:07:38.673748+0000 My*App[8461:465653] [] [0x7f9596053820] CVDisplayLink::stop 2022-03-07 20:07:38.673862+0000 My*App[8461:465653] [] [0x7f9596053820] Bad CurrentVBLDelta for display 1 is zero. defaulting to 60Hz. 2022-03-07 20:07:38.673883+0000 My*App[8461:465653] [] [0x7f9596053820] CVDisplayLink::start I really don't know how else to describe this. I can only imagine having to hand over the entire project as lately I've only been working on the storyboard file so how would this affect it? To be honest the only change I can see is my upgrade to OSX 12.2.1. It's definitely something to do with SpriteKit since not initialising a window with a scene in it stops the errors from showing.
Posted
by
Post not yet marked as solved
2 Replies
1.6k Views
HELLO WORLD! I am currently developing an amazing Unity mini Game. The game development has come to the deploying stage. Using Unity allows me to deploy this game on MacOS, iOS, Android and Windows which is fantastic . However, I really need this game to have the iOS widget extension as a key feature on mobile. Just like the "Steve" dinosaur game which can be played in widget. I had seen a lot of tutorials and youtube videos but still cant find a solution which make Unity iOS app into a widget. If I really want to make widget Game on iOS, do I need to develop the whole game all over again in xcode or using GameKit? Really hoping there's a way to simply convert the Unity iOS app into a widget.
Posted
by
Post not yet marked as solved
5 Replies
2.5k Views
Hello there 👋 I've noticed a different behavior between iOS 15 and iOS 16 using CIFilter and SpriteKit. Here is a sample code where I want to display a text and apply a blurry effect on the same text in the back of it. Here is the expected behavior (iOS 15): And the broken behavior on iOS 16: It looks like the text is rotated around the x-axis and way too deep. Here is the sample code: import UIKit import SpriteKit class ViewController: UIViewController {     var skView: SKView?     var scene: SKScene?     override func viewDidLoad() {         super.viewDidLoad()         skView = SKView(frame: view.frame)         scene = SKScene(size: skView?.bounds.size ?? .zero)         scene?.backgroundColor = UIColor.red         view.addSubview(skView!)         skView!.presentScene(scene)         let neonNode = SKNode()         let glowNode = SKEffectNode()         glowNode.shouldEnableEffects = true         glowNode.shouldRasterize = true         let blurFilter = CIFilter(name: "CIGaussianBlur")         blurFilter?.setValue(20, forKey: kCIInputRadiusKey)         glowNode.filter = blurFilter         glowNode.blendMode = .alpha         let labelNode = SKLabelNode(text: "MOJO")         labelNode.fontName = "HelveticaNeue-Medium"         labelNode.fontSize = 60         let labelNodeCopy = labelNode.copy() as! SKLabelNode         glowNode.addChild(labelNode)         neonNode.addChild(glowNode)         neonNode.addChild(labelNodeCopy)         neonNode.position = CGPoint(x: 200, y: 200)         scene?.addChild(neonNode) } }
Posted
by
Post not yet marked as solved
3 Replies
1.4k Views
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?
Posted
by
Post not yet marked as solved
0 Replies
706 Views
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
Posted
by
Post not yet marked as solved
0 Replies
567 Views
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?
Posted
by
wmk
Post not yet marked as solved
0 Replies
427 Views
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.
Posted
by
Post not yet marked as solved
1 Replies
890 Views
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)?
Posted
by
Post not yet marked as solved
1 Replies
586 Views
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
Posted
by
Post not yet marked as solved
0 Replies
474 Views
I have multiple images that at various times I need to replace a target image for a SKSpriteNode. Each of these multiple images has a different size. The target SKSpriteNode has a fixed frame that I want to stay fixed. This target is created via: myTarget = SKSpriteNode(imageNamed: “target”) myTarget.size = CGSize(…) myTarget.physicsBody = SKPhysicsBody(rectangleOf: myTarget.size) How do I resize each of the multiple images so that each fills up the target frame (expand or contract)? Pretend the target is a shoebox and each image is a balloon that expands or contracts to fill the shoebox. I have tried the following that fails, that is, it changes the size of the target to fit the new image .. in short, it does the exact opposite of what I want. let newTexture = SKTexture(imageNamed: newImage) let changeImgAction = SKAction.setTexture(newTexture, resize: true) myTarget.run(changeImgAction) Again, keep frame of myTarget fixed and change size of newTexture to fit the above frame ..
Posted
by
Post not yet marked as solved
3 Replies
896 Views
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) } }
Posted
by
Post not yet marked as solved
0 Replies
453 Views
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!
Posted
by
Post not yet marked as solved
1 Replies
559 Views
Hi, I'm creating a SF Symbols image like this: var img = UIImage(systemName: "x.circle" ,withConfiguration: symbolConfig)!.withTintColor(.red) In the debugger the image is really red. and I'm using this image to create a SKTexture: let shuffleTexture = SKTexture(image: img) The texture image is ALWAYS black and I have no idea how to change it's color. Nothing I've tried so far works. Any ideas how to solve this? Thank you! Best Regards, Frank
Posted
by
Post not yet marked as solved
0 Replies
478 Views
Xcode will try to open to the last opened project, which caused the crash, but it will just crash again. Any suggestions? Edit: I submitted the logs to apple and a restart did not resolve. Translated Report (Full Report Below) Process: Xcode [836] Path: /Applications/Xcode.app/Contents/MacOS/Xcode Identifier: com.apple.dt.Xcode Version: 14.3.1 (21815) Build Info: IDEFrameworks-21815000000000000~2 (14E300c) App Item ID: 497799835 App External ID: 857328487 Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2023-09-02 09:57:22.3965 -0400 OS Version: macOS 13.5.1 (22G90) Report Version: 12 Anonymous UUID: C53B443F-47B9-4610-5294-CDFB25DDE82B Time Awake Since Boot: 300 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_PROTECTION_FAILURE at 0x000000016b5d3fe0 Exception Codes: 0x0000000000000002, 0x000000016b5d3fe0 Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11 Terminating Process: exc handler [836] VM Region Info: 0x16b5d3fe0 is in 0x167dd0000-0x16b5d4000; bytes after start: 58736608 bytes before end: 31 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL mapped file 167dcc000-167dd0000 [ 16K] r--/rw- SM=COW ...t_id=d707e06b ---> STACK GUARD 167dd0000-16b5d4000 [ 56.0M] ---/rwx SM=NUL ... for thread 0 Stack 16b5d4000-16bdd0000 [ 8176K] rw-/rwx SM=PRV thread 0 Kernel Triage: VM - (arg = 0x0) pmap_enter retried due to resource shortage VM - (arg = 0x0) pmap_enter retried due to resource shortage VM - (arg = 0x0) pmap_enter retried due to resource shortage VM - (arg = 0x0) pmap_enter retried due to resource shortage
Posted
by