Post

Replies

Boosts

Views

Activity

Moving a SKSpriteNode image in response to a change in its position
Moving a SKSpriteNode image in response to a change in its position is not working. Based on the code below, does anyone have an idea why? N.B. I change the position of the image within my class GameScene. Then, I call, e.g., this function: func drawBall() {             let positionInSceneCoordinates = CGPoint(x: ballPosX, y: ballPosY)             myBall!.removeAction(forKey: "moveTO")     let moveTO = SKAction.move(to: positionInSceneCoordinates, duration: TimeInterval(1))     myBall!.run(moveTO, withKey: "moveTO)") } Selective placement of print statements prove that the ballPosX, ballPosY are changing as they should, but I am observing zero movement on the Xcode Simulator via the call to myBall!run(..). I am at a loss here on how to proceed. Thanks bunches!
4
0
534
Feb ’23
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
753
Jan ’23