为什么SKSpriteNode节点的node.frame.size.width比node.size.width小?

6
为什么SKSpriteNode节点的node.frame.size.width比node.size.width小?以下是示例代码,您可能需要插入自己的图像。
- (void)DrawRect:(SKSpriteNode *)node
{
SKShapeNode *rect = [[SKShapeNode alloc] init];

CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddRect(myPath, nil, node.frame);
rect.path = myPath;
rect.lineWidth = 1;

rect.strokeColor = [SKColor whiteColor];
rect.glowWidth = 0;
[self addChild:rect];
}

//这里绘制精灵

-(void) DrawSpriteNode
{
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"character"];
SKSpriteNode* node = (SKSpriteNode *)[SKSpriteNode spriteNodeWithTexture:[atlas         textureNamed:@"testimage.png"]];

node.position = CGPointMake(self.anchorPoint.x, self.anchorPoint.y);
NSLog(@"node frame width x :%f",node.frame.size.width);
NSLog(@"node frame height y :%f",node.frame.size.height);
NSLog(@"node width y :%f",node.size.width);
NSLog(@"node height y :%f",node.size.height);

node.anchorPoint = CGPointMake(0.5, 0.5);
[self DrawRect: node];
[self addChild:node];
}
1个回答

6
SKSpriteNode对象的size属性是一个特殊的属性,允许您显式地设置大小。 frame属性由SKNode对象使用其多个属性计算而来。以下引用摘自Apple针对SKNode对象的文档,SKSpriteNode继承自该对象:
“frame属性为节点的可视内容提供边界矩形,通过缩放和旋转属性进行修改。如果节点的类绘制内容,则框架不为空。每个节点子类以不同方式确定此内容的大小。在某些子类中,节点内容的大小被明确声明,例如SKSpriteNode类。在其他子类中,类使用其他对象属性隐式计算内容大小。例如,SKLabelNode对象使用标签的消息文本和字体特性确定其内容大小。”

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接