2013年9月12日星期四

[Android] Inherit CCSprite class , initialized error


recently with pop cap Bejeweled resources and thought cocos2d-x. Do not want to encounter a problem, I Caishuxueqian , really do not know quick solution , seeking help everyone to see.
write gems classes, inheritance CCSprite, as follows
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;
}
};

then initialize it in the game layer :

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

here to cause a problem.
If in debug mode (F5 to run ) , the program runs correctly.
But if the direct (CTRL + F5) , then "Stop Run" , the words of commissioning "heap is corrupted ", but occasionally can run .
the debug or release folder plus the resource file copy out , then run must be " stopped ."

put the above "block-> setWillRemove (false)" and "block-> setMoveStep (0)" remove it to run .
block-> setType (type) sentence Quedui program no effect , strange ah.
throughout the three days , did not find any reason .
seeking guidance about the great God . Grateful !




version 2.1.4 and 2.1.4f have used this issue.
------ Solution ---------------------------------------- ----
write your own constructor
------ eference --------------------------- ------------
ccsprite initialization and declaration will inherit a lot of problems .
proposal does not inherit ccsprite, but will ccspirte as your class below a variable

没有评论:

发表评论