最近用pop cap的宝石迷阵资源练练cocos2d-x。不想遇到个问题,本人才疏学浅,实在不知道咋解决,求大伙帮忙看看。
写宝石类,继承CCSprite,如下
class CCBlock : public cocos2d::CCSprite
{
public:
JewelType type;
int moveStep;
bool bWillRemove;
void removeSelf()
{
this->removeFromParentAndCleanup(true);
}public:
JewelType getType()
{
return type;
}
void setType(int value)
{
this->type = (JewelType)value;
}
bool getWillRemove()
{
return bWillRemove;
}
void setWillRemove(bool b)
{
bWillRemove = b;
}
int getMoveStep()
{
return moveStep;
}
void setMoveStep(int step)
{
moveStep = step;
}
};
然后在游戏层中初始化它:void GameLayer::initBlocks()
{
srand(time(NULL));
for(int i=0; i<BLOCKHEIGHT; i++)
for(int j=0; j<BLOCKWIDTH; j++)
{
int type = rand()%7 + 1;
CCBlock* block = (CCBlock*)CCBlock::createWithSpriteFrameName(CCString::createWithFormat("Jewel%d.png", type)->getCString());
block->retain();
block->setPosition(ccp(313 + 60*j, 104 + 60*i));
block->setType(type);
block->setWillRemove(false);// <==== 这里出问题了
block->setMoveStep(0);// <==== 还有这里
block->setTag(1000 + (i+1)*8 + j +1);
jewelSheet->addChild(block);
}
}这里就出现问题了。
如果在调试模式下(F5运行),程序可以正常运行。
但是如果直接(CTRL+F5)的话,就“停止运行”,调试的话说的“堆已损坏”,但偶然也能运行。
把debug或者release文件夹加上资源文件拷出去的话,运行一定是“停止运行”。把上面的“block->setWillRemove(false)” 和 “block->setMoveStep(0)”去掉的话能运行。
block->setType(type)这句 却对程序没什么影响,诡异啊。
整了2、3天,也没找到什么原因。
求大神指点一下。感激不尽!
版本用的2.1.4 和2.1.4f均有这个问题。cocos2d-xc++宝石迷阵堆已损坏
解决方案 »
- iOS中如何根据输入的文字动态改变textView的宽度和高度?
- 如何保存类中的字符串变量,求解,请教各位
- 请教UIImagePickerController
- ucenter开发的网站移植到ios平台
- 程序进入后台,再回到前台,tableView刷新崩溃[UIImage isKindOfClass:]message sent to deallocated
- 新手-delegatew问题
- 【关于推送通知】请问在APP主进程未启动时,可以用推送通知来启动APP么?
- UIWebView导航条本地化问题
- 16进制字符串转ascii码
- 开发过程中在一个UITableView中嵌套一个tableView所遇到的问题
- 关于block的很诡异的问题
- 自定义tableViewCell 的复用问题
建议不继承ccsprite,而是将ccspirte作为你的类下面的一个变量