我的筆記若對你有幫助希望評論或者支持下。比較亂,以後再開始分類整理把(*^__^*) 嘻嘻……
1在添加新的層在原背景上面時候(模態窗口),在cocosbuilder中 應該新建爲node格式 而不是layer 否則 會彈出
CCNodeLoaderMap::iterator ccNodeLoadersIterator =this->mCCNodeLoaders.find(pClassName);
assert(ccNodeLoadersIterator !=this->mCCNodeLoaders.end());
return ccNodeLoadersIterator->second;
2期待下一個問題出現,哈哈
a,問題出現了,要彈出一個新層,此層有大小以及位置。在cocosbuilder中可以設置node的錨點位置,例如設置到中間位置的錨點爲anchor point -0.5,-0.5.但是經過操作發現這樣設置的話 在代碼中設置層的位置變得難於理解,例如 偏左上角node->setPosition(ccp(-50,
-30));
所以默認0,0 最好,將精靈都放在這個node中 在代碼中設置 node位置(想要將node放在哪就放哪)。
b,對node縮放 同理 於sprite :pClickItem->setScaleX(0.1),pClickItem->setScaleY(0.1); -》 node->setScaleX(0.5),node->setScaleY(0.5);
3移除所在父類窗口(層/node)
this->removeFromParentAndCleanup(true);
void 類名::onEnter(){
CCLog("CCAlert::onEnter()");
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -128, true);
CCLayer::onEnter();
}
void 類名::onExit(){
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
}
boolXXX::ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent){
return true;
}
void XXX::ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent){
}
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -100, true);
此時效果->左右均可觸摸5記錄存儲數據
CCUserDefault::sharedUserDefault()->setStringForKey("name","nishihou");
CCUserDefault::sharedUserDefault()->flush();//這裏一定要提交寫入哦,否則不會記錄到xml中,下次啓動遊戲就獲取不到value了。
//這裏隨便定義一個string爲了驗證我們的存儲
std::string str="select";
//取出我們剛存儲的nishihou,然後賦值給str驗證下;
str= CCUserDefault::sharedUserDefault()->getStringForKey("name");
CCLog("打印str=:%s",str.c_str());
// CCLog("打印str=:%s",CCUserDefault::sharedUserDefault()->getStringForKey("key").c_str());
文件存儲的地址可以使用CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str()獲得。
刪除數據 ,設爲空即可
CCUserDefault::sharedUserDefault()->setStringForKey("key","");
CCUserDefault::sharedUserDefault()->flush();
6報錯
Apple Mach-O Linker (id) Error : linker command failed with exit code 1 (use -v to see invocation)
This generally means that another instance of this process was already running or is hung in the debugger.(lldb)
void場景::update(float dt)
{
for(int i =0; i <數組名->count(); i++)
{
場景 * 精靈2 = (場景*)數組名->objectAtIndex(i);
if((精靈1->boundingBox()).intersectsRect(精靈2->boundingBox()))
{ int diantag = dian->getTag();
int yezitag = diantag+100;
if (getChildByTag(yezitag)!=NULL)
{
CCSprite *yezi = (CCSprite *)getChildByTag(yezitag);//強轉
this->removeChild(yezi,true);
}else {
CCLog("%d========%d",diantag,yezitag);
}
_dians->removeObject(dian);
this->removeChild(dian,true);
}
else
{
// CCLog("沒碰撞");
}
}
}
onNodeLoaded裏 例如
this->schedule(schedule_selector(YeZiScene::update));與
_yezis = CCArray::create();
for (int i=1;i<=9;i++)
{
int tag =100+i;
if (getChildByTag(tag)!=NULL)
{
CCSprite *sprite = (CCSprite *)getChildByTag(tag);//強轉
_yezis->addObject(sprite);
}
}等等 順序爲 先加載遊戲界面 然後加載數組 之後循環
int diantag = dian->getTag();
int yezitag = diantag+100;
if (getChildByTag(yezitag)!=NULL)
{
CCSprite *yezi = (CCSprite *)getChildByTag(yezitag);//強轉
this->removeChild(yezi,true);
}else {
CCLog("%d========%d",diantag,yezitag);
}
CCPoint location=pTouch->getLocation();
//設置執行動作需要移動到的位置,參數1代表時間 2位置
float juli=ccpDistance(qiu->getPosition(),ccp(location.x,location.y));
float sudu=100.0;
CCActionInterval* actionMove =CCMoveTo::create(juli*1.0/sudu,ccp(location.x,location.y));
CCFiniteTimeAction* actionMoveDone =CCCallFuncN::create(this,
callfuncN_selector(YeZiScene::spriteMoveFinished));
qiu->runAction(CCSequence::create(actionMove, actionMoveDone,NULL) );
}
int diantag = dian->getTag();
int yezitag = diantag+100;
float juli=ccpDistance(qiu->getPosition(),ccp(location.x,location.y));
。。。反正老多了要這樣做 要養成習慣 仔細看代碼裏面 大多數都是private:
CCSprite* ciqiu;
在.cpp中初始化處寫:
CCSprite*ciqiu = (CCSprite*)getChildByTag(196);本想着 以後在用到精靈時候不需要寫了,可是結果是NO
終於明白:羣裏說的,“你再次聲明並定義了 雖然名字是一樣的 但是是2個完全不同的對象啊,一個是類成員 一個是臨時,臨時的那個隨着函數的消失就消失了,你在.h裏面聲明 是代表你這個類的類成員。 你在.cpp裏面寫的那個東西是 一個臨時的變量”
解決方法:初始化中
把你前面的 CCsprite * 全部去掉。。