Random Already added

Hi!
i would make a CCsprite to a CCSprite with a CCarray->RandomObject() but when i add it to this, it says that it has already been added
my code:
for init
getrand(100, 200);
getrand(300, 300);
here’s my getrand() defination:
CCSprite getrand(int y, int x)
{
CCSprite* spriteR = array->randomObject();
spriteR->setPosition(ccp(int x, int y));
this->addchild(spriteR, 1);
}

use CCArray *pArray = this->getChildren() to find already added children’s, and iterate over pArray objects and compare each with CCSprite* spriteR = array->randomObject();, if it matches then you don’t need to add Sprite again.

thanks!!!
but i do not really understand, can u please make the CCSprite getRand() function and send the code…plzzzz:) :slight_smile: :slight_smile: :slight_smile: :slight_smile:

someone PLZ help me:(

PLZZZZZZZZZZZZZZZZZZZ

You can try this

CCSprite getrand(int y, int x)
{
CCSprite* spriteR = array->randomObject();
spriteR->setPosition(ccp(int x, int y));
this->addchild(spriteR, 1);
array->removeObject(spriteR);
}

TYYYYYYY xD
It worked!:slight_smile: