Reputation: 23
SKShapeNode are created in the firm of bubbles, which may be moved by tapping. The project works when launched on iOS 8, touches are being proceeded correctly. When launching on iOS 9, the bubbles are being created and the physics works correctly (when created, the bubbles bounce from each other). But they don’t react on tap, touchesBegan:withEvent: is not evoked. The compiler doesn’t generate an error. If someone ever faced such an issue and had solved, or knows the solution, please let me know.
That’s how I create the bubbles:
// при создании изначальное положение по горизонтали выбирается рандомно
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];
Method 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];
}
What’s the matter?
Upvotes: 1
Views: 569
Reputation: 7252
Two main things that can causes this issue:
userInteractionEnabled
is set to falseUpvotes: 1