0

Cocos2d does not allow two similar objects to be added as child of self is there another way of adding a duplicate without implementing deep copy in my DigBackground class? and doing (DigBackground *)[idObject copy];

btw! isn´t this racism against twins?

DigBackground *bgImage = (DigBackground *)idObject;
[self addChild:bgImage z:iterator tag:iterator];

                // Add duplicate sprite
DigBackground *bgImage2 = (DigBackground *)idObject;
[self addChild:bgImage z:iterator tag:iterator]; // Not allowed - duplicate child
1
  • your example is not a duplicate (nor "similar") object, it's the same object. Since afaik cocos2d only implemented NSCopying for actions you can only create another obj with the same info like busta says
    – CodeSmile
    Apr 26, 2013 at 9:26

1 Answer 1

1

you can't add a sprite who already added, in the last line you add the same first child.

but if changing that doesn't works, you can create another sprite with the same information (i suppose DigBackground is a CCSprite):

DigBackground *bgImage = (DigBackground *)idObject;
[self addChild:bgImage z:iterator tag:iterator];

// Add duplicate sprite
DigBackground *bgImage2 = [DigBackground spriteWithTexture:[bgImage texture] rect:[bgImage boundingBox]];
[self addChild:bgImage2 z:iterator tag:iterator+1]; //the tag should be unique.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.