0

So I got a NSLog, which gets location of touch in view

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 
for (UITouch *touch in touches)
{
    CGPoint location=CGPointMake([touch locationInView:self.view].x,fabs(height-[touch locationInView:self.view].y));
    NSLog(@"Touched:%f %f",location.x,location.y);                     

After That I check if the touch is in labels

if ([upgradeLabel containsPoint:location])
   {     [self checkAvailable];
       countUpgrade+=1;
       if (countUpgrade%2==1)
       {
           upgradeLabel.fontColor=[SKColor greenColor];
           [self upgradeButton:true];
       }
       else
       {
           upgradeLabel.fontColor=[SKColor redColor];
           [self upgradeButton:false];
       }
   }
   //-upgradeLabel
    if ([dollarPerSecUp containsPoint:location])
    {
        up1=true;
        up2=false;
        up3=false;
        up4=false;
        up5=false;
        [self checkUpgrades];
    }

It got an output when I touch on upgradeLabel, but when I touch on dollarPerSecUp label there is no output and the code isn't working. User interaction enabled in both labels

Fominykh Maxim
  • 485
  • 1
  • 6
  • 20

2 Answers2

0

Instead of location you can detect node with the code below.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];
}
mkeremkeskin
  • 644
  • 10
  • 27
  • Thanks. But still I can't handle touches in the 2nd label for whatever reason. In touchesMoved it's working but not in touchesBegan – Fominykh Maxim Nov 06 '15 at 08:49
0

The problem was in setting userInteractionEnabled.

Fominykh Maxim
  • 485
  • 1
  • 6
  • 20