Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when tap on cell of Machine #4

Open
quochn-RisingStar opened this issue Apr 17, 2024 · 1 comment
Open

Bug when tap on cell of Machine #4

quochn-RisingStar opened this issue Apr 17, 2024 · 1 comment

Comments

@quochn-RisingStar
Copy link

quochn-RisingStar commented Apr 17, 2024

when i tap on cell of machine it will be replace by my icon
Video:

Simulator.mp4
@quochn-RisingStar
Copy link
Author

quochn-RisingStar commented Apr 17, 2024

@eleev
I fixed it but i don't have access permission.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {   
      for touch in touches {
          let location = touch.location(in: self)
          let selectedNode = self.atPoint(location)
          var node: SKSpriteNode
          
          if let name = selectedNode.name {
              if name == Constants.reset || name == Constants.resetLabel {
                  self.stateMachine.enter(StartGameState.self)
                  return
              }
          }
          
          if gameBoard.isPlayerOne() {
              guard selectedNode.children.isEmpty else { return } // fixed here
              let cross = SKSpriteNode(imageNamed: Constants.exCell)
              cross.size = CGSize(width: Constants.cellSize, height: Constants.cellSize)
//                cross.zRotation = CGFloat.pi / 4.0
              node = cross
          } else {
              let circle = SKSpriteNode(imageNamed: Constants.ouCell)
              circle.size = CGSize(width: Constants.cellSize, height: Constants.cellSize)
              node = circle
          }
          
          node.alpha = 0.0
          let reveal = SKAction.fadeAlpha(to: 1.0, duration: 0.5)
          node.run(reveal)
          
          for i in 0...8 {
              guard let cellNode: SKSpriteNode = self.childNode(withName: gameBoard.getElementAtBoardLocation(i).node) as? SKSpriteNode else { return }
              if selectedNode.name == cellNode.name {
                  cellNode.addChild(node)
                  gameBoard.addPlayerValueAtBoardLocation(i, value: gameBoard.isPlayerOne() ? .x : .o)
                  gameBoard.togglePlayer()
              }
          }
      }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant