我正在开发一个使用cocos2d-x的android游戏。在主菜单层,我已经放置了一个背景图像,一个播放按钮,我还使用了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时,播放按钮无法执行指定的功能
发布于 2014-08-26 21:20:41
我不知道问题出在哪里,但是
particle->release();是如此的奇怪
粒子将被释放两次
https://stackoverflow.com/questions/25482920
复制相似问题