SpriteKit,iOS 9.方法touchesBegan:withEvent:在SKScene中调用

时间:2015-10-16 07:32:33

标签: sprite-kit ios9 xcode7 touchesbegan

SKShapeNode是在气泡公司中创建的,可以通过点击来移动。该项目在iOS 8上启动时正常工作,触摸正在正确进行。在iOS 9上启动时,正在创建气泡并且物理工作正常(创建时,气泡彼此反弹)。但是他们没有做出反应,触摸开始:withEvent:没有被唤起。编译器不会生成错误。如果有人遇到过这样的问题并且已经解决了,或者知道解决方案,请告诉我。

这就是我创建气泡的方式:

// при создании изначальное положение по горизонтали выбирается рандомно
SKShapeNode *ballPhysics = [[SKShapeNode alloc] init];
CGPathRef ballPhysicsPath = CGPathCreateWithEllipseInRect(CGRectMake( - ballRadius, - ballRadius, ballRadius * 2.f, ballRadius * 2.f), 0);
ballPhysics.path = ballPhysicsPath;
ballPhysics.position = CGPointMake(self.frame.size.width/2.f - 20.f + (arc4random() % 40), 6.f*self.frame.size.height/5.f);
ballPhysics.zPosition = 0;

// ширина линии, цвет и имя шарика
ballPhysics.lineWidth = 3;
ballPhysics.strokeColor = task.color;
ballPhysics.fillColor = [SKColor whiteColor];
ballPhysics.name = task.ballIdentifier;

// физическое тело
CGPathRef ballPhysicsBodyPath = CGPathCreateWithEllipseInRect(CGRectMake( - ballRadius - 2, - ballRadius - 2, ballRadius * 2.f + 4, ballRadius * 2.f + 4), 0);
ballPhysics.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath: ballPhysicsBodyPath];
ballPhysics.physicsBody.dynamic = YES;
ballPhysics.physicsBody.restitution = 0.0f;
ballPhysics.physicsBody.mass = 0.1f;
ballPhysics.physicsBody.friction = 0.0f;
ballPhysics.physicsBody.categoryBitMask = ballCategory;
ballPhysics.physicsBody.collisionBitMask = ballCategory | funnelCategory | edgeCategory;
ballPhysics.physicsBody.contactTestBitMask = ballCategory | funnelCategory | edgeCategory;
ballPhysics.physicsBody.allowsRotation = NO;
ballPhysics.physicsBody.usesPreciseCollisionDetection = YES;

// добавляем объект на сцену
[self addChild:ballPhysics];

方法touchesBegan:withEvent:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInNode:self];
    SKNode *touchedNode = [self nodeAtPoint:touchLocation];

    if ([touchedNode.name hasPrefix:@"ball_"])
    {
        self.touch = touch;
        self.selectedNode = (SKShapeNode *) touchedNode;
        self.selectedNode.physicsBody.mass = 0.3f;
        return;
    }

    // говорим делегату, что было касание между шарами
    if ([self.delegateMovingBalls respondsToSelector:@selector(touchesBetweenBalls)])
        [self.delegateMovingBalls touchesBetweenBalls];
}

什么事?

1 个答案:

答案 0 :(得分:1)

可能导致此问题的两个主要因素:

  1. userInteractionEnabled设置为false
  2. 您有一个顶部视图阻止底层内容接收触摸。