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];
}
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With