遇到问题集锦(无c++基础 零起点小小小菜鸟亲身经历) 转自http://blog.csdn.net/qq592116366
来源:互联网 发布:数学 知乎 编辑:程序博客网 时间:2024/05/20 05:54
我的笔记若对你有帮助希望评论或者支持下。比较乱,以后再开始分类整理把(*^__^*) 嘻嘻……
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 * 全部去掉。。
- 遇到问题集锦(无c++基础 零起点小小小菜鸟亲身经历) 转自http://blog.csdn.net/qq592116366
- 遇到问题集锦(无c++基础 零起点小小小菜鸟亲身经历)
- selenium使用中遇到的问题,转自:http://blog.csdn.net/funi16/article/details/9036753
- 转自http://blog.csdn.net/lihao21
- Linux shell脚本编写基础 转自:http://blog.csdn.net/fpmystar/article/details/4183678
- 嵌入式c程序易错点(转自http://blog.csdn.net/zhzht19861011/article/details/45508029)
- 140个Google面试问题(转自http://blog.csdn.net/bopgroup/article/details/6514423)
- Maven 专题之一 (转自http://blog.csdn.net/maoxiang)
- 转自 http://blog.csdn.net/coollofty/article/details/8058859
- 转自http://blog.csdn.net/rookieding/article/details/7639898
- 转自http://blog.csdn.net/mazhaojuan/article/details/7660657
- lua错误总结 转自http://blog.csdn.net/chenrunhua
- 转自: http://blog.csdn.net/ahuier/article/details/8982516
- 转自: http://blog.csdn.net/xiaxiaorui2003/article/details/3838631
- 转自 http://blog.csdn.net/gnehcuoz/article/details/52686824
- 转自 http://blog.csdn.net/g_brightboy/article/details/14229139
- 转载自http://blog.csdn.net/dongfengsun
- 遇到问题集锦(记录5.15--6.1)——>零起点做起
- 时间的获取
- 第五届河南省大学生程序设计竞赛题解(第一次群赛兼妇女节专场)
- VMware vSphere 常见问题解答整理
- SeekBar使用5
- Shell编程中Shift的用法
- 遇到问题集锦(无c++基础 零起点小小小菜鸟亲身经历) 转自http://blog.csdn.net/qq592116366
- 字符串的应用1
- POJ 3189 Treats for the Cows(两种DP方法解决)
- servlet webservice 比较
- Android NDK开发Crash错误定位
- 数字字符转化整数
- 编译和安装的常见问题
- vim常用命令
- 使用Jquery实现图片轮播效果