Can't tap SKSpriteNode - no touch detected ios

后端 未结 4 571
萌比男神i
萌比男神i 2021-01-12 08:49

I am pretty new to iOS, objective C and working with Xcode. I only did one simple news type app, but now I would like to create a game I had published on another platform.

4条回答
  •  天涯浪人
    2021-01-12 09:14

    Your code is essentially correct. Just a few minor changes are required.

    You have implemented the -touchesBegan: method in your scene class. If you want to handle touches from within the scene class, then all the child nodes should have the userInteractionEnabled property set to NO. A sprite node's userInteractionEnabled property should be set to YES only when it is capable of handling touches on it's own.

    So, in your case you should make the following changes:

    1 - Set the spriteNode's userInteraction to NO.

    mySKSpriteNode.userInteractionEnabled = NO;
    

    2 - Change the way you check for your own sprite.

    if([node isEqual: mySKSpriteNode])
    

    You will find your code is working as intended.

提交回复
热议问题