What is the best way to have a SKSpriteNode composed of multiple images ?

I found that [SKTexture textureWithImage:image]; doesn't use the scale property (when I use it with a custom bitmap assembled image I have a small SKSpriteNode).

Maybe I can create a link between multiples SKSpriteNode but I'm not sure it is a good idea for collisions detection.

EDIT:

Solution that works for me.
This code takes 3 textures, draw them in the GraphicsContext that creates a UIImage.
Then I add this UIImage to my SKNode which now have multiple textures. However, it is very important to specify the SKNode size property [self setSize:CGSizeMake(WIDTH_HERO, HEIGHT_HERO)]; in my case. If you dont, the node will use a bad scale factor and you'll have small textures (non retina).

CGSize mergedSize = CGSizeMake(WIDTH_HERO, HEIGHT_HERO);
UIGraphicsBeginImageContextWithOptions(mergedSize, NO, 0.0f);

[textureImage1 drawInRect:CGRectMake(0, 0, WIDTH_HERO, textureImage1.size.height)];
[textureImage2 drawInRect:CGRectMake(0, 40, WIDTH_HERO, textureImage2.size.height)];
[textureImage3 drawInRect:CGRectMake(0, 0, WIDTH_HERO, textureImage3.size.height)];

UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self setTexture:[SKTexture textureWithImage:mergedImage]];
有帮助吗?

解决方案

You can create another SKSpriteNode with the next texture and call addChild: on the original node, then change the position of the new node relative to the parent node.

This is inside my subclass of SKSpriteNode;

    UIImage* bottom = [[UIImage imageNamed: @"obstacle_base"] resizableImageWithCapInsets: UIEdgeInsetsMake(0, 0, 0, 0)];
    UIImage* top = [UIImage imageNamed: @"obstacle_top"];

    SKTexture* bottomT = [SKTexture textureWithImage: bottom];
    SKTexture* topT = [SKTexture textureWithImage: top];

    [self setTexture: bottomT];

    // create top
    SKSpriteNode* topNode = [[SKSpriteNode alloc] initWithTexture: topT];
    topNode.position = CGPointMake(0, height/2 - topNode.size.height/2);
    [self addChild: topNode];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top