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学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1