Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SKSpriteNode node.frame.size.width is smaller than node.size.width?

Why SKSpriteNode node.frame.size.width is smaller than node.size.width ?
Here is example code ,probably you will need to insert your own image

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

//here draw the sprite

-(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];
}
like image 802
Sureyya Uslu Avatar asked Dec 21 '13 17:12

Sureyya Uslu


1 Answers

The size property of the SKSpriteNode object is a special property that allows you to set the size explicitly. The frame propert is calculated by the SKNode object using several of it's properties. The following quote is from Apple's documentation for the SKNode object, which SKSpriteNode inherits from:

"The frame property provides the bounding rectangle for a node’s visual content, modified by the scale and rotation properties. The frame is non-empty if the node’s class draws content. Each node subclass determines the size of this content differently. In some subclasses, the size of the node’s content is declared explicitly, such as in the SKSpriteNode class. In other subclasses, the content size is calculated implicitly by the class using other object properties. For example, a SKLabelNode object determines its content size using the label’s message text and font characteristics."

like image 134
Brian Shamblen Avatar answered Oct 30 '22 16:10

Brian Shamblen