B.Ticca
B.Ticca

Reputation: 23

touchesBegan in specific area(Swift)

I would like to create the rocket spawn for space game with override func touchesbegan is spritekit. But the rocket will only spawn if the specific part of the screen is touched(f.e. image), not the whole screen.

Upvotes: 0

Views: 450

Answers (1)

Josh Homann
Josh Homann

Reputation: 16327

  override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let area = CGRect(x: 0, y: 0, width: 100, height: 100)
    guard let point = touches.first?.location(in: view),
          area.contains(point) else {
      return
    }
    //Spawn Logic Here
  }

Upvotes: 1

Related Questions