【问题标题】:Why SKSpriteNode node.frame.size.width is smaller than node.size.width?为什么 SKSpriteNode node.frame.size.width 小于 node.size.width?
【发布时间】:2013-12-21 17:22:29
【问题描述】:

为什么 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];
}

【问题讨论】:

    标签: ios sprite-kit skspritenode


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 2018-04-01
      • 2020-03-16
      • 2013-11-04
      相关资源
      最近更新 更多