Bug jumping over obstacles - SCHOOL PROJECT :(

Hey friends, I recently went through the “How To Make A Game Like Flappy Bird” Tutorials. Although I do understand they are dated, I would love some help. The game is completed and looks great although I realized you can jump off screen over the obstacles entirely. Even when I download the completed version, same issues… Help smh

Thanks!

Hi @iosdeveloperisaac,
Most of the sample, tutorial code are written to illustrate and help users understand something, which is mainly basic. Most of the tutorial writers take care to check for issues, however there can be edge cases that slip through.

However I don’t understand the problem you are mentioning, so if you detail it with the code or a screenshot/video someone can respond better.

cheers,

1 Like

Thanks for the reply! Do you have any recommendations on who I could reach out to on here for help?

Hi. I think I maybe able to help. It sounds like you are able to jump up off the top of the screen. What device are you running it. Is it an actual iPhone or simulator?

In GameScene.swift there is a method called setBackground(). There is a field called playableStart and playableHeight. Print out the playableHeight. I bet that it is off screen. Try running it on different devices also.
Another spot to look is in GameViewController.swift. In the method viewWillLayoutSubviews() there is where it Print out the Aspect Ratio.

This fields will give us enough information to figure out what is happen. I will work with you to get this resolved. I’m Nick nice to meet you.

1 Like

Hey Nick! Thanks for the reply. It is like this on the simulator as well as multiple iPhones I’ve tested on.

All my background code in the “GameScene” is as follows

  func setupBackground() {
let background = SKSpriteNode(imageNamed: "Background")
background.anchorPoint = CGPoint(x: 0.5, y: 1.0)
background.position = CGPoint(x: size.width / 2, y: size.height)
background.zPosition = Layer.background.rawValue

playableStart = size.height - background.size.height
playableHeight = background.size.height

worldNode.addChild(background)

// Add Physics
let lowerLeft = CGPoint(x: 0, y: playableStart)
let lowerRight = CGPoint(x: size.width, y: playableStart)
physicsBody = SKPhysicsBody(edgeFrom: lowerLeft, to: lowerRight)
physicsBody?.categoryBitMask = PhysicsCategory.Ground
physicsBody?.collisionBitMask = 0
physicsBody?.contactTestBitMask = PhysicsCategory.Player

}

All the relevant code in “GameViewController” is as follows

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

if let skView = self.view as? SKView {
  if skView.scene == nil {
    let aspectRatio = skView.bounds.size.height / skView.bounds.size.width
    let scene = GameScene(size: CGSize(width: 320, height: 320 * aspectRatio), stateClass: MainMenuState.self, delegate: self)

    skView.showsFPS = false
    skView.showsNodeCount = false
    skView.showsPhysics = false
    skView.ignoresSiblingOrder = true

    scene.scaleMode = .aspectFit

    skView.presentScene(scene)
  }
}

}

Thanks for your help!

I’ve added some code to the thread. Maybe that will help you?

Does the code I posted help?

he code looks right Try this as a test. Change this line of code below in the setBackground. We are trying to determine if the issue is with your playableHeight being wrong or if it is an issue with the code that uses the playableHeight to determine if it is off the screen. What this will do is only let your bird fly between the ground and 200 points above the ground. So it should not go very high. I’m in the process of downloading Xcode 8 on another mac i have so i can see what you seeing.

// playableHeight = background.size.height

playableHeight = playableStart + 200

1 Like

I have downloaded flappy bird on another Mac. I see that you can fly off the screen. Give me today and I will send you a solution.

1 Like

Thank you so much for your help, I will try what you posted in the meantime.

Let me know what you come up with!

Here is a fix that should run on all iPhones except for any of the iPhone X’s.Try it with iPhone 6, 7 and 8 it should work. This code was written before the iPhone X’s where announced. When I have time i will get it working on those but I will not have time today to do it.

under component folder there is a program MovementComponent.swift.
in method applyMovement please the add code that’s starts with // Add to // END
at the bottom of the method.

/ Temporary Ground Hit
if spriteNode.position.y - spriteNode.size.height / 2 < playableStart {
spriteNode.position = CGPoint(x: spriteNode.position.x, y: playableStart + spriteNode.size.height / 2)
}

// Add this block of code
// off screen
let background = SKSpriteNode(imageNamed: “Background”)
let playableHeight = background.size.height
if spriteNode.position.y - spriteNode.size.height / 2 >= playableHeight + 100{
spriteNode.position = CGPoint(x: spriteNode.position.x, y: playableHeight + 100)
}
// End of block of code

}

override func update(deltaTime seconds: TimeInterval) {

Let me know if it behaves the way you want it to.

Thank You
Nick

Below I attached a screen shot with the errors that produced

blank out both double quotes and use your keyboard double quotes. Sometimes when you copy and paste they get converted If that does not work That same line of code is in GameScene in setBackground method Just copy and paste from there

That worked! Man thanks so much, have been stuck on this for WAY to long!

great it work for some reason they never put the code in to stop your character from flying up and over. if you get stuck again email me at dominicdaws@gmail.com

Have a great day
Nick

Check your email.

Thanks again.

Hey my friend, that fix worked great. Did you ever have a chance to brainstorm a potential solution for larger viewports like iPhone X?

Cheers!

This topic was automatically closed after 166 days. New replies are no longer allowed.