0

我正在使用 cocos2d-x 开发一个安卓游戏。在主菜单层我放了一个背景图像,一个播放按钮,我还使用 CCSpriteParticleSystem 类来展示一些降雪效果。我面临的问题是,当我将 CCParticleSystem 对象作为子对象添加到主层时,播放按钮将停止工作。当我点击播放按钮时,出现黑屏并关闭游戏。谁能帮帮我吗

代码如下:

     //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);

在此代码段中,使用了多个函数。buttonWithText(..) 创建一个带有一些文本的按钮。问题是,当我添加 CCParticleSystem 时,播放按钮不执行分配的功能

4

1 回答 1

0

我无法弄清楚问题是什么,但是

particle->release();

好奇怪

粒子将被释放两次

于 2014-08-26T13:20:40.630 回答