Post

Replies

Boosts

Views

Activity

PlaySound below crashes with this error: AddInstanceForFactory: No factory registered for id
Problem = PlaySound below crashes with this error: AddInstanceForFactory: No factory registered for id Setting a breakpoint before the guard let url block = NO error. Setting a breakpoint after the guard let url block = error!!, coupled with a horrible static sound happening. Note that if I set NO breakpoints, the correct sound happens but with the above error. What am I missing? Within my SKScene Class: func controllerInputDetected(gamepad: GCExtendedGamepad, element: GCControllerElement, index: Int) { // rightShoulder if (gamepad.rightShoulder == element) { if (gamepad.rightShoulder.value != 0) { startGame() } } } As shown above, I call the following function by pressing a shoulder button on my Gamepad: func startGame() { PlaySound(theSoundName: "roar") } func PlaySound(theSoundName: String) { guard let url = Bundle.main.url(forResource: "audio/" + theSoundName, withExtension: "mp3") else { print("sound not found") return } do { try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) itsSoundPlayer = try AVAudioPlayer(contentsOf: url) if theSoundName == "roar" { itsSoundPlayer?.numberOfLoops = -1 // forever } itsSoundPlayer!.play() } catch let error as NSError { print("error: \(error.localizedDescription)") } } Again, what am I missing?
1
0
967
Jan ’23
Cannot add a iOS Distribution Certificate to my Project or Target?
Cannot add a iOS Distribution Certificate to my Project or Target? During the Submission for Review process, it states I should choose a Build (for Distribution) and I need to do the above add before I can do that. Here is a screen shot of my Certificates set in my Developer Account: Here is the screen shot when I double-click on the iOS Distribution Certificate above: Here is a screen shot of that Certificate in the Finder: Yet in spite of all the above evidence, here is a screen shot of my Target for both my iOS and tvOS Project: So, please provide some hints because this is the only step left before I finally submit my App to the App store.
3
0
2.4k
Feb ’23
How can I make my Game App appear under Games in the App Store and not under Apps?
The reason I ask centers on the fact that my "Monster Paddle Pong" has been uploaded to the App Store - and it works! BTW: Search within Apps - not Games! Within Xcode I selected App Category = Games and the above search agrees with that. My question = how can I in the future make my Game appear under Games in the App Store and not under Apps?
1
0
651
Feb ’23
With Xcode 14.2, I unpaired my apple tv and now the apple tv does not show
With Xcode 14.2, had trouble pairing with my Apple TV (latest update). It continuously showed "Not Connected". So, I unpaired my apple tv and now the ATV does not show under Devices and Simulators. My ATV shows as the Target of my Xcode Project My Ventura 13.3 iMac mirrors to my ATV just great, but not my Xcode 14.2. Have turned off my ATV, quit Xcode and Shutdown and then re-started my iMac and no luck. Help desperately needed. Other posts seem to show an identical problem experienced by others.
1
0
937
Apr ’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
1k
May ’24
Cannot look at contents of file in Print Queue with Sonoma
Cannot look at contents of file in Print Queue with Sonoma Before Sonoma, after I selected print in a application, e.g., Word, I could double click on the document stored in the Print Queue and the pages would be displayed. With Sonoma, cannot see file contents?? One last thing pertaining to this Print Queue = I can't delete any of the accumulated "Completed" Jobs .. menu item to delete selected Jobs is dimmed??
0
0
779
Oct ’23
Where do I place my code to instantiate my Project’s `struct` code within `SwiftUI`?
Where do I place my code to instantiate my Project’s struct code within SwiftUI? As you can see way below, I call: _ = StaticObjects() Within GameScene’s didMove It seems the reason I don’t see the same #Preview image in my GameScene is that I am not explicitly returning a SwiftUI some View within my struct layout. I do know that didMove is really called .. but I just don’t see anything within the Simulator My #Preview works great: The following code appears within GameScene.swift of my Xcode Project: import SpriteKit import SwiftUI struct StaticObjects : View { // some View is returned when our struct is instantiated var body: some View { let theBuildings = ["hotel", "saloon", "watertower", "jail", "farmhouse", "barn"] let theFigures = ["desperado", "sheriff", "space", "space", "horse", "guy"] VStack { HStack(alignment: .bottom) { ForEach(theBuildings, id: \.self) { theBuilding in Image(theBuilding) .resizable() // for rotation .scaledToFit() .zIndex(2) Spacer() } // ForEach } // HStack for theBuildings HStack(alignment: .bottom) { ForEach(theFigures, id: \.self) { theFigure in Image(theFigure) .resizable() // for rotation .frame(width: 120, height: 230) .offset(x: 0.0, y: -50.0) .zIndex(2) Spacer() } // ForEach } // HStack for theFigures // aligns vertically the entire struct to the top Spacer() } // VStack } // body: } // struct StaticObjects /* #Preview { StaticObjects() } */ class GameScene: SKScene, SKPhysicsContactDelegate { override func sceneDidLoad() { super.sceneDidLoad() } // sceneDidLoad override func didMove(to view: SKView) { super.didMove(to:view) physicsWorld.contactDelegate = self _ = StaticObjects() // doesn’t work } // didMove func didBegin(_ contact: SKPhysicsContact) { // ... } // didBegin } // class GameScene
2
0
444
Dec ’23
Can you access the objects in a struct from outside the struct?
Can you access the objects in a struct from outside the struct? So far I have a group of HStacks and VStacks whose embedded objects are all Images(“name”). By definition these Images are fixed in terms of their .position and .size for example. Can I dynamically access these embedded objects from outside the struct? In short, move them? .. or include a Node so I could change its color? All changes made from Swift outside the struct?
1
0
508
Dec ’23
Resetting position and size of SKSpriteNodes with *every* rotation??
Do I really have to reset position and size of SKSpriteNodes with every rotation between landscape and portrait layout?? I've done that and it works .. but this seems to be overkill that the writers of Xcode internally compensated for .. vs. having the individual programmer having to do it. I have a getGameParms() which resets positions based on: #if os(iOS) && !targetEnvironment(macCatalyst) func getGameParms() { let roomRect = UIScreen.main.bounds roomWidth = roomRect.width * roomScale roomHeight = roomRect.height * roomScale if (thisSceneName == "GameScene") { if UIDevice.current.orientation.isLandscape { // changes here } else { // changes } } // if (thisSceneName == "GameScene") } // getGameParms #elseif os(tvOS) func getGameParms() { let roomRect = UIScreen.main.bounds roomWidth = roomRect.width * roomScale roomHeight = roomRect.height * roomScale if (thisSceneName == "GameScene") { // other changes here } } // getGameParms #endif Again, the burdensome changes are done .. but are they really necessary? As an alternative, I have called getGameParms() just once within my viewDidLoad() and the results are not correct. For example, I place one SKSpriteNode at the very bottom of the UIScreen and it does not stay there with UIDevice rotation. I also size it horizontally such that it expands to the full width of the UIScreen. Rotation destroys that. if getGameParms() is called only once as just described. Some explanation as to why would be appreciated.
0
0
488
Dec ’23
UIBezierPath *not* showing?
I am developing a game in which my Locomotive is following a UIBezierPath that mimics an oval shaped Track. The math of the following is not "adding up" .. if it is, I am obviously not understanding the math of the layout. Bottom line = the following code does not display the UIBezierPath. Here's the code that creates this UIBezierPath .. please note the math in the comments: func createTrainPath() { trackRect = CGRect(x: 0.0, y: 0.0 - roomHeight/2 + tracksHeight, width: tracksWidth, height: tracksHeight) // trackRect = (0.0, -207.0, 940.0, 476.0) // portrait // trackRect = (0.0, -274.0, 470.0, 238.0) // landscape print("trackRect = \(trackRect!)") trackPath = UIBezierPath(ovalIn: trackRect) let theTrackShapeNode = SKShapeNode(path: trackPath.cgPath, centered: true) theTrackShapeNode.zPosition = 100 // for testing theTrackShapeNode.position = myTracks.position theTrackShapeNode.lineWidth = 4.0 theTrackShapeNode.strokeColor = SKColor.blue if let ourScene = GameScene(fileNamed: "GameScene") { print("here") // this shows ourScene.addChild(theTrackShapeNode) // does *not* show? } } // createTrainPath In Portrait mode, the UIScreen measures 1024 x 1366 and the Track measures 940 x 476 with its top edge down 207 from the center of the UIScreen. In Landscape mode, the UIScreen measures 1366 x 1024 and the Track measures 470 x 238 with its top edge down 274 from the center of the UIScreen. In both modes, the bottom edge of the Track is supposed to be flush with the bottom edge of the UIScreen .. and it is. If the math is correct, then I am obviously not understanding the math of the layout .. because the UIBezierPath is not showing. The math appears correct .. but the UIBezierPath just is not showing. So where is my brain off-center?
3
0
716
Dec ’23
How to attach a struct to the main GameViewController?
How to attach a struct to the main GameViewController? This struct occupies the top half of the main ViewController. The goal is to have this struct be part of the main GameViewController and not in separate UIHostingController. SO, when I rotate the main SKScene for example the struct also rotates OR when I switch SKScenes both the top-half struct and the bottom-half switch together because they are one SKScene. The programmer who invented HStacks and VStacks is a blooming genius … but I need to avoid what I have now which is the HStack VStack combo closing and then its neighbors in the main SKScene closing. Here are the essential code segments - all in my GameViewController: Declared at the top: var useGSO = false var gsoChildVC: UIViewController! // = UIHostingController override func viewDidLoad() { showScene() /* "gso" = "Game Static Objects" */ if useGSO { // create a UIHostingController and extract a rootView for later processing gsoChildVC = UIHostingController(rootView: GameStaticObjects()) } } // viewDidLoad Within my showScene(): func addGamePieces(toScene: SKScene) { if thisSceneName == "GameScene" { // various SKSpriteNodes // // STATIC People, Animals and Buildings // are now added to the top of our SKScene // addGSOChild(toScene: toScene) } // if thisSceneName == "GameScene" else { removeGSOChild() } } // addGamePieces func addGSOChild(toScene: SKScene) { // gsoChildVC = nil *if* useGSO = false guard gsoChildVC == nil else { let gsoParentVC = self // parent = us = GameViewController // default value // gsoChildVC.view.translatesAutoresizingMaskIntoConstraints = true /**/ let sameWidth = gsoParentVC.view.bounds.width let newHeight = 0.5 * gsoParentVC.view.bounds.height let boundsWithNewBottom = CGRectMake(0.0, 0.0, sameWidth, newHeight) gsoChildVC.view.frame = boundsWithNewBottom /**/ // first, add the view of the hild to the view of the parent gsoParentVC.view.addSubview(gsoChildVC.view) // then, add the child to the parent gsoParentVC.addChild(gsoChildVC) // notify the child ViewController that we're finished gsoChildVC.didMove(toParent: gsoParentVC) return } } // addGSOChild func removeGSOChild() { // gsoChildVC = nil *if* useGSO = false guard gsoChildVC == nil else { // First, remove the Child from its Parent gsoChildVC.removeFromParent() // Then, remove the Child's view from the Parent's gsoChildVC.view.removeFromSuperview() return } } // removeGSOChild As stated at the top of this OP, the HStack and Stack code appears great .. but the UIHostingController is distinct from my GameViewController. As a direct result, such operations as switching SKScenes is done in 2 halves - (1) the HStack and Stack top half and (2) whatever non-struct stuff appears below it. If I switch SKScenes, I want both halves to switch as one entity. FWIW, the struct that contains the HStack and Stack code is outside the GameViewController class as suggested by Apple. and as specified above, I call: gsoChildVC = UIHostingController(rootView: GameStaticObjects()) within my viewDidLoad() method. I would love some basic guidance here as to what basic error I am making.
0
0
456
Dec ’23