I have this Sprite Kit game that passes some balls across the screen and the user has to tap them. If the user misses a ball and it goes off the screen then they lose.
The game works perfect when testing it on my iPhone but when I run it on my iPad it doesn't work as it's supposed to. It also doesn't work on iPhone X simulator. When the game first starts up it goes to the Start Scene, but when the user clicks "Start Game" it goes to the Game Scene and then automatically cuts to the game over scene without spawning any balls. After I hit "Play again" it will spawn the balls as it should but the measurements of detecting if the balls are out of bounds are not correct (which they are when testing on my iPhone 8 Plus).
Here are the areas where I think the problem may be coming. This is where the widths for things come from.
EnumerateChildNodes function to remove the balls once of the scene:
func searchChildNodes() { self.enumerateChildNodes(withName: "BALL") { (node: SKNode, nil) in if node.position.x < -25 || node.position.x > self.size.width + 25 { print("balls Out") node.removeFromParent() let transition = SKTransition.fade(withDuration: 1) self.gameScene = SKScene(fileNamed: "GameOverScene") self.gameScene.scaleMode = .aspectFit self.view?.presentScene(self.gameScene, transition: transition) } } }
Specifically in the if statement
:
if node.position.x < -25 || node.position.x > self.size.width + 25
If remove the part after the ||
operator then the game lets the balls do what they are supposed, only without detecting if the are out of bounds on the right side of the screen.
Update
Here is the code that sets the position of the balls when they are spawned:
if ballDirection == "right" { player?.position.x = 0 moveRight() } else { player?.position.x = (self.scene!.frame.size.height) moveLeft() }
0 comments:
Post a Comment