SpriteKit

RSS for tag

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

Posts under SpriteKit tag

45 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Can't hear CAF Audio in running app
I have an unusual situation. I'm working through some self study training and this particular project is a game similar to fruit ninja where things are flying around the screen and you slice through them by swiping your finger. Anyway the instructor provided a series of "*.caf" files for various sounds while playing the game. For some reason I can't hear any of the sounds on my personal Mac when running the app via Xcode to either an iOS iPad simulator or to a real iPad that I have attached to my mac and setup for developer use in Xcode. Yes sound is working on the mac (hear new email come in etc. and can play videos in the browser). In the iPad simulator I can play youtube videos in mobile safari. While adjusting the sound doesn't seem to raise or lower the volume I can hear the audio in the youtube videos. On the real iPad: yes the sound is on and I can hear audio while playing videos in the browser etc. Lastly, I pushed the code up to GitHub and pulled it to my work Mac. There the sound plays just find in the iOS iPad simulator on that Mac (not allowed to attach my personal iPad to my work mac so can't try the iPad there). So I fell like this confirms the code is correct for playing the sounds in the running app. Oh, and I can select the file in left nav and click the little play button icon to hear it played in Xcode. so, I feel like this is an issue on my personal Mac with Xcode etc., but I'm at a loss as to what the issue is. Can anyone suggest some things to look for on my Mac to get sound working in this app? if you want to see the code it's here and the free training i'm following is at https://www.hackingwithswift.com/100/77. TIA
3
0
642
Dec ’23
SpriteKit - Associating sound with motion
I need to associate sound with the movement of a sprite. Movement can be as a result of physics, not as a result of an SKAction. When the object is sliding thee should be sliding sound throughout the time when it is sliding, and then a different sound when it bumps into a rock and goes up in the air. When the object is airborne, there is no sound, till it falls again - a falling sound, and then slides down with a sliding sound. The sounds associated with the collision ( rock, ground and so on ) are straightforward and work fine. But am having difficulty associating the sound with movement. The closest result I have is to check the velocity of the sprite's physics body every update cycle and play or stop the sound based on whether the velocity is greater than zero. I tried SKAction.playSoundFileNamed first - the sound kept going even when the object was not moving. I tried adding an SKAudioNode with Play and Stop, with no better result. I finally tried using AVAudioPlayer to play and Pause , which yielded the best results, but the sliding sound still played past the sliding action. What is the best way to do this? My code for playing the sound is as follows: var blockSliding = false for block in gameBlocks { if (block.physicsBody?.velocity.dx ?? 0) + (ball.physicsBody?.velocity.dy ?? 0) > 0.05 { blockSliding = true break } } if slideSound.isPlaying { if !blockSliding { slideSound.pause() } } else { if blockSliding { slideSound.play() } } I have setup slideSound earlier loading the appropriate sound file into an AVAudioPlayer
0
0
472
Nov ’23
ProRes4444 with alpha not work using AVPlayer
I have a ProRes 4444 format video with an alpha channel. The circle in the middle of the video is completely opaque, while the rest is fully transparent. Everything looks normal in iMovie, as I can see the background through the surrounding parts. However, when I play it using AVPlayer, the parts that are supposed to be fully transparent appear somewhat opaque, as shown in the image below: I used the official project provided by Apple named 'using_hevc_video_with_alpha', but I only replaced the HEVC with alpha format file with a ProRes 4444 format video file. Below is the main code. import Cocoa import SpriteKit import AVFoundation class ViewController: NSViewController { @IBOutlet var skView: SKView! var videoPlayer: AVPlayer! override func viewDidLoad() { super.viewDidLoad() if let view = self.skView { // Load the SKScene from 'backgroundScene.sks' guard let scene = SKScene(fileNamed: "backgroundScene") else { print ("Could not create a background scene") return } // Set the scale mode to scale to fit the window scene.scaleMode = .aspectFill // Present the scene view.presentScene(scene) // Add the video node guard let alphaMovieURL = Bundle.main.url(forResource: "xuewang", withExtension: "mov") else { print("Failed to overlay alpha movie on the background") return } videoPlayer = AVPlayer(url: alphaMovieURL) let video = SKVideoNode(avPlayer: videoPlayer) video.size = CGSize(width: view.frame.width, height: view.frame.height) print( "Video size is %f x %f", video.size.width, video.size.height) scene.addChild(video) // Play video videoPlayer.play() } } }
0
0
585
Nov ’23
Unable to use SpriteKit with Swift Playground Books
All our custom Playground Books using SpriteKit stopped working after upgrading to SwiftPlaygrounds version 4.4 To reproduce the issue, simply create a new book by clicking the top right hand icon and in the book add two lines of code. import SpriteKit let circle = SKShapeNode(circleOfRadius: 100.0) The second line produces an error. I tried with other classes. SKAction seems to work. SKSpriteNode, SKTexture etc have the same issue. Please help. Our students are stuck!
2
0
737
Oct ’23
err: [0x159dec540|RoomCongruence::Processor|Processor] One or more of the chosen IR Presets does not contain room congruence data or the data is corrupted.
mac mini 2018, MAC OS Ventura 13.5.2, Xcode 15.0 im running my game app in iPhone SE(3rd gen) device(not simulator) with IOS 17 and getting the following error in console: [0x159dec540|RoomCongruence::Processor|Processor] One or more of the chosen IR Presets does not contain room congruence data or the data is corrupted. err shows in console among this other errs messages: getFilePtr: error -1 getting file status [Room Congruence] isIrDataUserDataDictionaryStructurallyValid: IRData User Data invalid - underlying CF object is nil. [0x159dec540|RoomCongruence::Processor|Processor] One or more of the chosen IR Presets does not contain room congruence data or the data is corrupted. the error is showing only(one time) when user have started a game, but not showing if user select to play again. app have been tested on IOS 15 and 16 but not showing this error. appreciate any help, i can provide any other data as necessary. Sorry if im may be missing any info or data necessary this my first time posting here, thanks.
0
0
596
Oct ’23
err:[Room Congruence] isIrDataUserDataDictionaryStructurallyValid: IRData User Data invalid - underlying CF object is nil.
mac mini 2018, MAC OS Ventura 13.5.2, Xcode 15.0 using SpriteKit im running my game app in iPhone SE(3rd gen) device(not simulator) with IOS 17 and getting the following error in console: [Room Congruence] isIrDataUserDataDictionaryStructurallyValid: IRData User Data invalid - underlying CF object is nil. the error is showing only(one time) when user have started a game, but not showing if user select to play again. the error is showing among the following console errs: getFilePtr: error -1 getting file status [Room Congruence] isIrDataUserDataDictionaryStructurallyValid: IRData User Data invalid - underlying CF object is nil. [0x159dec540|RoomCongruence::Processor|Processor] One or more of the chosen IR Presets does not contain room congruence data or the data is corrupted. app have been tested on IOS 15 and 16 but not showing this error. appreciate any help, i can provide any other data as necessary. Sorry if im may be missing any info or data necessary this my first time posting here, thanks.
0
1
577
Oct ’23
Overlapping in Tilemap
Hi all So I'm quite new into GameDev and am struggling a bit with the Tilemap All my elements have the size of 64x64. As you can see in my screenshot there is some gap between the street and the water. It might be simple but what's the best way to fix that gap? I could increase the width of the left and right edge png but then I will sooner or later run into other problems as it then is not fitting with the rest. Thanks for your help Cheers from Switzerland
2
0
712
May ’24
Can a physical body be partially contained by an edge-loop body?
I have a sprite kit scene with an edge loop physics body set programmatically with the category bit mask set to a custom Physics Category called Edge. Through the scene editor, I've added several sprite nodes with varying physics body types and various category masks and collision masks. The collision mask for a particular sprite node includes the Edge category. Initially, I have this node partially off the screen on the scene editor but when I run the program, it appears completely inside the edge loop. Is it possible to have a sprite node be positioned partially inside the edge loop and partially outside the edge loop?
0
0
444
Sep ’23
Different methods of animating shape along custom path?
I'm trying to animate a shape (e.g. a circle) to follow a custom path, and struggling to find the best way of doing this. I've had a look at the animation options from SwiftUI, UIKit and SpriteKit and all seem very limited in what paths you can provide. Given the complexity of my path, I was hoping there'd be a way of providing a set of coordinates in some input file and have the shape follow that, but maybe that's too ambitious. I was wondering if this were even possible, and assuming not, if there were other options I could consider.
1
0
897
Jan ’24
Xcode Won't Launch After Crash
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
1
0
572
Sep ’23
SKTexture renders SF Symbols image always black
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
1
0
724
Aug ’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!
0
0
547
Aug ’23
How do I resize a new image to an existing Sprite?
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 ..
1
0
687
May ’24
How do you incorporate WKInterfaceSKScene into a watchOS Starter Template App?
I'm trying to create a Apple Watch game using Xcode 14.2 and watchOS 9. Getting started creating a watchOS AppΒ seems pretty straight forward, and getting started creating a game project via the starter templateΒ seems easy enough. Trying to put these two together though doesn't seem to work (or is not straight foward). The documentation specifies limitations on what libraries can be used with watchOS notingΒ WKInterfaceSKScene, but doesn't give any specific examples of how to start out a WatchOS project using this. Additionally nearly every online tutorial that I'm able to find uses Storyboards to create a watchOS game, which does not seem to be supported in the latest version of watchOS or Xcode. Can anyone provide example starter code using the watchOS App project starter that that loads with a small colored square on the screen that moves from left to right using the WKInterfaceSKScene library? I've tried theΒ Apple documentation, asking ChatGPT for a sample or reference links, and various tutorials on YouTube and elsewhere.
2
1
1k
2w