SKShapeNode.containsPoint(p: CGPoint) not working properly

Swift | XCode 7.3

I have two buttons in the MenuScene, which both are SKShapeNode. I am using the touchesEnded function to check whether a button was pressed.

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
  if let touch = touches.first {
    let position = touch.locationInView(view)

    if firstButton.containsPoint(position) {
        let someScene = SomeScene(size: view!.bounds.size)
    } else if secondButton.containsPoint(position) {
        let anotherScene = AnotherScene(size: view!.bounds.size)

This worked just fine. However, when I changed the button’s position (not during the game, I deleted the old code and replaced it with a new one), something weird happened.

As the simulator presents the MenuScene, the buttons do not work. However, the old locations, which DOES NOT EXIST in my code, trigger the buttons.

I cannot see how the function can cause this to happen. I have tried restarting my computer, without luck. If you need more information, please let me know. In advance, thanks!

First thing to try is deleting the app from the simulator and then build it again. The Simulator is sort of known for doing odd things some times.

So the buttons are in a new position, but the old position is resolving in touchesEnded?

If you wouldn’t mind posting more that might help, like the creation of the buttons. What you have should work fine as far as the code you posted goes.

Thanks for helping!

I tried deleting the app from the simulator, still no luck. I’ve runned the app on my iPhone with the same thing happening.

HOWEVER, I discovered something weird but useful. I changed the location of the buttons, and it affected the the locations that reacted. It works as a mirror! Putting a button at the bottom of the screen caused the upper part to trigger the scenechanging function. Why is this so? I may find some way to make the right locations trigger the buttons, but it would be nice to be able to solve the issue more handy.

Again, thank you for involving!

That sort of sounds like the positions need to be converted to the node space of your scene.

Difficult to say without seeing a little more code.