Adding more Child to main CCLayer causes other child not function properly

61 Views Asked by At

I am developing an android game using cocos2d-x. In the main menu layer I have put on a background image, a play button and i have also used CCSpriteParticleSystem class to show some snow fall effect. The Problem I am facing is that when I add CCParticleSystem object as a child to main layer then the play button stops working. when I click on play button a black screen appears and game is closed. Can anyone please help me

The Code is As follows:

     //Particle SYstem for snow fall effect 
     CCParticleSystem *particle = CCParticleSnow::create();
     particle->initWithTotalParticles(2000);

     particle->release();

     particle->setTexture(CCTextureCache::sharedTextureCache()->addImage("star.png"));

     particle->setPosition(ccp(Utils::s().height - 10, Utils::s().height - 10));


    this->addChild(particle,1);

     //now including a sprite sheet and then setting the background image
     s = CCDirector::sharedDirector()->getWinSize();

    CCString* file = (Utils::getArtScaleFactor() > 1) ? CCString::create("img-hd.plist") : CCString::create("img.plist");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(file->getCString());

    file = (Utils::getArtScaleFactor() > 1) ? CCString::create("main-hd.png") : CCString::create("main.png");
    CCSprite *bg = CCSprite::create(file->getCString());
    bg->setPosition(ccp(s.width/2,s.height/2));
    Utils::scaleSprite(bg);
    this->addChild(bg,-1);

    //below code creates a play button 

    CCMenuItemSprite *playButton =     CCMenuItemSprite::create(GameButton::buttonWithText("PLAY!",false), NULL, this, menu_selector(MainMenu::playGame));
    CCMenu *menu = CCMenu::create(playButton,NULL);
    menu->setPosition(ccp(s.width/2,s.height/2 - s.height/4.0f));

    this->addChild(menu,2);

in this code snippet, there are multiple functions used. buttonWithText(..) creates a button with some text on it. The problem is, when i add the CCParticleSystem , the the Play button does not performs the assigned function

1

There are 1 best solutions below

0
On

i can't figure out what the problem is, but the

particle->release();

is so odd

the particle will be released twice