I'm currently trying to use a stretchable image on a SKSpriteNode.
Typically, strechable images are returned by the method UIImage::resizableImageWithCapInsets:
So i wrote that code:
SKTexture * texture = [SKTexture textureWithImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)]];
SKSpriteNode * node = [SKSpriteNode spriteNodeWithTexture:texture size:CGSizeMake(150, 8)];
But it don't work. The node streaches itself without taking Edge Insets into account. Is it only possible?
Use the
centerRectproperty ofSKSpriteNode. Assuming your texture is 50 pixels wide and you want not to stretch the leftmost and rightmost 10 pixels:centerRectis specified in unit coordinates of the texture. More info here under "Resizing a Sprite."