1

I have created two nodes one circle with 4 segments and one rotating bar. when the user touches the screen I want to detect if the bar is pointing to the right color or the wrong ones.

I tried checking the distance between the nodes but the bar's position is not changing and also the distance is always the same. I am not sure what I am missing.

enter image description here

I am creating the circle and bar like this

Bar
    colorBar = createImage()
    changeColor()
    colorBar!.colorBlendFactor = 1.0
    colorBar!.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 300))
    colorBar!.physicsBody?.affectedByGravity = false
    colorBar!.position = CGPoint(x: self.frame.midX , y: self.frame.midY)
    colorBar!.anchorPoint = CGPoint(x: 0.5, y: 1.0)
    colorWheel!.addChild(colorBar!)

Circle

    for i in 0...3 {
        let section = SKShapeNode(path: path.cgPath)
        section.fillColor = colors![i]
        section.strokeColor = colors![i]
        section.name = colorNames[i]
        section.zRotation = rotationFactor * CGFloat(i);
        container.addChild(section)
    }
Sekhar
  • 341
  • 2
  • 13
  • One solution is making a raycast like this answer https://stackoverflow.com/questions/60137122/create-a-raycast-in-spritekit/60624699#60624699 – Maetschl Sep 15 '20 at 01:08

1 Answers1

2

Instead of using one image for your circle, divide your image into 4 nodes and assign a physicsbody to all of them separately. This way you can detect whether your colorbar node is touching the specific colour node .

Stefan Ovomate
  • 511
  • 1
  • 4
  • 16