0
votes

I have just started using cocos2d and can't solve this one nice by myself.

I want to create a sprite, add another sprite as it child, and then display it all. I wan't to change their size also, as my images are to big for my screen so I am scaling my sprites. The problem is that when I scale my parent sprite its scale is applied to child, so simple scaling isn't a solution, I need to change actual texture. I am kinda stack right now. Can anybody help me?

    CCSprite* parent = [CCSprite spriteWithFile: @"some_picture.png"];
    parent.position = ccp(300, 300);
    [parent setSizeX:400 andY:400]; //currently this function added in category just scales sprite

    CCSprite* child = [CCSprite spriteWithFile: @"some_other_picture.png"];
    child.position = ccp(200, 200);
    [child setSizeX:200 andY:200]; //currently this function added in category just scales sprite


    [parent addChild:child];
    [someCCLayer addChild:parent];

So I need a solution for this set size function.

Many thanks!

1
There is no other way besides scaling the image. Changing the texture is technically still scaling it. This issue sounds like you have to get back to the drawing board, figure out what you really want to do, and then you'll likely find a solution that's dead easy. I think you're approaching this problem the wrong way. Keep in mind that you can scale each node individually, and still have them follow each other.LearnCocos2D

1 Answers

0
votes

All transforms of any CCNode subclass are applied to it's children. You should not change this. So you can add your sprites to one parent.

If you want to have possibility to transform both your sprites(move, rotate, etc.) simultaneously, you can create your own control, for example, simple CCNode subclass, that will contain both sprites