Swift + SpriteKit – Button is clickable even when not visible

Solutions Collect From Internet About “Swift + SpriteKit – Button is clickable even when not visible”

It seems that whether or not the node is added to the parent, containsPoint method will behave the same. Means, it will always return true if the given point lies inside of parent’s (in your case, button’s) coordinate system.

You can check this by initializing the attackButton without adding it to the scene. If you tap in the lower left corner of the scene, the message from the touchesBegan will be still printed.

I guess, this is happening because of the fact that each node has its position property set to CGPoint(0,0) by default. Also, in your case, the button has its size. And it will have its size and position set even if it’s not added to its parent (or if removed from its parent) because it is obviously defined as a property and there is a strong reference to it.