cocos2d-x 障碍与路线的双重控制
来源:未知 责任编辑:责任编辑 发表时间:2014-04-20 03:36 点击:次
/****************************ci************************************************************************************/
void JlmLayer::ciCreate(float dt)
{
CCTMXObjectGroup* objGroup =((PmdInAllLayer*)this->getParent())->_mapLayer->_allMap->objectGroupNamed("ci");
CCArray* objArray = objGroup->getObjects();
if( objArray&& objArray->count()>0)
{
CCObject* pObj = NULL;
CCARRAY_FOREACH(objArray, pObj)
{
CCDictionary* playerPointDic= (CCDictionary*)pObj; //将对象转化成字典,便于获取键值
float x = playerPointDic->valueForKey("x")->floatValue();
float y = playerPointDic->valueForKey("y")->floatValue();
this->_ci=CCSprite::createWithSpriteFrameName("ci.png");
this->_jlmBatchNode->addChild(this->_ci);
this->_ciArray->addObject(this->_ci);
this->_ci->setPosition(ccp(1.8f*x,1.8f*y));
this->_ci->setScale(0.6f);
}
}
this->_isJlmCreate=true;
if(this->_isJlmCreate)
{
unschedule(schedule_selector(JlmLayer::ciCreate));
}
}
void JlmLayer::ciZhuAi(float dt)
{
if(this->_isJlmCreate)
{
CCSize mapTiledNum = ((PmdInAllLayer*)this->getParent())->_mapLayer->_allMap->getMapSize();
CCSize tiledSize = ((PmdInAllLayer*)this->getParent())->_mapLayer->_allMap->getTileSize();
CCPoint point1 =((PmdInAllLayer*)this->getParent())->_jlmLayer->_jlmSprite->getPosition();
int x =0.5*point1.x / tiledSize.width;
int y =0.5*point1.y / tiledSize.height;
/* Cocos2d-x的默认Y坐标是由下至上的,所以要做一个相减操作 */
y = mapTiledNum.height - y;
int tiledGid=((PmdInAllLayer*)this->getParent())->_mapLayer->_allMap->layerNamed("fangluoxia")->tileGIDAt(ccp(x,y));
if(tiledGid!=0)
{
CCDictionary* propertiesDict = ((PmdInAllLayer*)this->getParent())->_mapLayer->_allMap->propertiesForGID(tiledGid);
/* 取得格子的zhezhao属性值 */
const CCString* prop = propertiesDict->valueForKey("zhangai");
/* 判断zhezhao属性是否为true,是的话,不让玩家移动 */
if(prop->m_sString.compare("true") == 0) {
this->_jlmSprite->_spedV=CCPointZero;
}
}
}
}
void JlmLayer::ciRemove(CCNode* spend)
{
CCSprite* sprite =(CCSprite*)spend;
this->_ciArray->removeObject(sprite,true);
this->_jlmBatchNode->removeChild(sprite,true);
}
/*****************************************************************************************************************/

相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>

![cocos2d_x+lua[2]](/uploads/allimg/131030/110J64609-0-lp.jpg)








