The SKShapeNode frame contains a point (0, 0), even if CGPath is not

I am implementing a game that dynamically loads a background image depending on the visible area. The background is drawn using SKShapeNode. To save memory, I draw only a small part of CGPath. The problem is that no matter what CGPath coordinates I use, the resulting SKShapeNode frame will always contain a point (0, 0). Here is an example:

SKShapeNode *shapeNodePos = [SKShapeNode node];
CGMutablePathRef pathPos = CGPathCreateMutable();
CGPathAddRect(pathPos, NULL, CGRectMake(50, 50, 50, 50));
shapeNodePos.path = pathPos;
CGPathRelease(pathPos);
NSLog(@"Frame pos = (%f, %f, %f, %f)", shapeNodePos.frame.origin.x, shapeNodePos.frame.origin.y, shapeNodePos.frame.size.width, shapeNodePos.frame.size.height);

Result:

Frame pos = (0.000000, 0.000000, 100.000000, 100.000000)

However, I would expect SKShapeNode.frame to be limited only by CGPath content:

Frame pos = (50.000000, 50.000000, 50.000000, 50.000000)

Is this a bug in SpriteKit or is it actually expected behavior? If this small CGPath rectangle extends significantly far from the point (0, 0), it can also negatively affect the performance or will the Sprite Kit ignore the empty area of ​​the frame?

Thanks in advance!

+4
1

, node CGMutablePathRef, (0,0). , node, .

SKShapeNode *shapeNodePos = [SKShapeNode node];
shapeNodePos.position = CGPointMake(50, 50); // <<< Set node position
CGMutablePathRef pathPos = CGPathCreateMutable();
CGPathAddRect(pathPos, NULL, CGRectMake(0, 0, 50, 50));
shapeNodePos.path = pathPos;
CGPathRelease(pathPos);

NSLog

pos = (50.000000, 50.000000, 50.000000, 50.000000)

+1

Source: https://habr.com/ru/post/1536327/


All Articles