0

I am trying to make a flappy bird look alike off of a youtube video ( https://www.youtube.com/watch?v=D7ntzPFvMf0) and it was made in swift 2. I am attempting to do this in swift 3. Everything has been going smoothly until i reached the touch began function.

All prior physics behaviors were working like is affected by gravity. When touch began is clicked nothing happens. I tested to see if it is even working by printing and it is. So I'm trying to get my datBoi to jump when clicked. As a note the video had me put

datBoi.physicsBody?.applyImpulse(CGVectorMake( 0, 100)) 

but I replaced it with what I know have

CGVector(dx: 0,dy: 100)

as this seems to be expired in swift 3.

Any help is appreciated here is my code concerning the datBoi object.

struct PhysicsCategory
    {
        static let datBoi : UInt32 = 0x1 << 1
        static let Ground : UInt32 = 0x1 << 2
        static let Wall : UInt32 = 0x1 << 3
    }

  class GameScene: SKScene 
  {

    var Ground = SKSpriteNode()
    var datBoi = SKSpriteNode()

    override func didMove(to view: SKView)
    {
        datBoi = SKSpriteNode(imageNamed: "datboi")
        datBoi.size = CGSize(width: 150, height: 240)
        datBoi.position = CGPoint(x: -85, y: 0)

        datBoi.physicsBody = SKPhysicsBody(rectangleOf: datBoi.size)
        datBoi.physicsBody?.categoryBitMask = PhysicsCategory.datBoi
        datBoi.physicsBody?.collisionBitMask = PhysicsCategory.Ground | PhysicsCategory.Wall
        datBoi.physicsBody?.contactTestBitMask = PhysicsCategory.Ground | PhysicsCategory.Wall
        datBoi.physicsBody?.affectedByGravity = true
        datBoi.physicsBody?.isDynamic = true
        datBoi.zPosition = 2
        self.addChild(datBoi)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
    {
        datBoi.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        datBoi.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 100))
        print("hi")
    }
  }
marcomk
  • 9
  • 5
Sam R.
  • 1
  • 2

1 Answers1

0
    Circle.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
    Circle.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 74))  //Also  try affected by gravity to false
shane
  • 342
  • 1
  • 5
  • 28