问题描述
- cocos2d-x CCArrary问题导致系统崩溃
-
请大家帮忙看看,m_monsterArr的状态貌似不对,但不知道哪里错了,报错的内容好像是无法认领childMonsterManager.h private: CCArray *m_monsterArr; //存放怪物对象列表 MonsterManager.cpp void MonsterManager::createMonsters(){ m_monsterArr = CCArray::create(); m_monsterArr->retain(); CCLOG("count is %d",m_monsterArr->count()); Monster *monster = NULL; CCSprite *sprite = NULL; //for(int i = 0;i<MAX_MONSTER_NUM;i++)F for(int i = 0;i<2;i++){ /*创建怪物对象*/ monster = Monster::create(); monster->bindSprite(CCSprite::create("monster.png")); monster->reset(); /*添加怪物对象*/ this->addChild(monster); /*保存怪物对象到列表中,方便管理*/ m_monsterArr->addObject(monster); } } 主函数 bool TollgateScene::init(){ bool bRet = false; do{ CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); /*游戏标题图片*/ CCSprite *titleSprite = CCSprite::create("title.png"); titleSprite->setPosition(ccp(visibleSize.width/2,visibleSize.height - 50)); this->addChild(titleSprite,2); /*创建主角*/ m_player = Player::create(); m_player->bindSprite(CCSprite::create("sprite.png")); m_player->setPosition(ccp(visibleSize.width/2 - 120,visibleSize.height/2 - 120)); //m_player->setPosition(ccp(200,visibleSize.height/4)); this->addChild(m_player,3); /*初始化背景图片*/ initBG(); /*创建Jump按钮*/ //createJumpBtn(); /*妖怪管理器*/ MonsterManager *monsterMgr = MonsterManager::create(); //monsterMgr = MonsterManager::create(); this->addChild(monsterMgr,4);-->运行到这里报错 /*每一帧调用scheduleUpdate*/ this->scheduleUpdate(); bRet = true; }while(0); return bRet; }
运行完“MonsterManager *monsterMgr = MonsterManager::create()”后的状态以及错误报告
解决方案
CCarray你要删除的话 不能随意从中间删除,这是他数据结构的问题
时间: 2024-11-02 12:35:07