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];
}
4

1 回答 1

6

SKSpriteNode 对象的size属性是一个特殊属性,允许您显式设置大小。该frame属性是由 SKNode 对象使用它的几个属性计算的。以下引用来自 Apple 的 SKNode 对象文档,SKSpriteNode 继承自该对象:

“框架属性为节点的可视内容提供边界矩形,由缩放和旋转属性修改。如果节点的类绘制内容,则框架是非空的。每个节点子类确定此内容的大小不同。在某些子类中,节点内容的大小是显式声明的,例如在 SKSpriteNode 类中。在其他子类中,内容大小由该类使用其他对象属性隐式计算。例如,SKLabelNode 对象使用标签的消息文本确定其内容大小和字体特征。”

于 2013-12-21T18:13:32.847 回答