当前位置: 首页>>代码示例>>C++>>正文


C++ CCTMXTiledMap::getPosition方法代码示例

本文整理汇总了C++中CCTMXTiledMap::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXTiledMap::getPosition方法的具体用法?C++ CCTMXTiledMap::getPosition怎么用?C++ CCTMXTiledMap::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCTMXTiledMap的用法示例。


在下文中一共展示了CCTMXTiledMap::getPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ccTouchesBegan

void MapScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint m_tBeginPos = touch->getLocationInView();    
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
    char mch[256];
	CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	CCPoint mapp = map->getPosition();
    //获得触摸点位置在地图上的索引(行列)
	CCPoint aimmapindex = convertto2d(m_tBeginPos.x - mapp.x,m_tBeginPos.y - mapp.y);
	if(aimmapindex.x < 0 || aimmapindex.y < 0 || aimmapindex.x >= map->getMapSize().width || aimmapindex.y >= map->getMapSize().height)
	{
		return;
	}
	CCPoint herop = m_tamara->getPosition();
	CCPoint mapindex = convertto2d(herop.x,herop.y);
	CCTMXLayer* layer = map->layerNamed("grass");
	int tilegid = layer->tileGIDAt(ccp(aimmapindex.x,aimmapindex.y));
	CCDictionary *tiledic = map->propertiesForGID(tilegid);
	CCString *mvalue = (CCString *)tiledic->objectForKey("conflict");
	int mv = mvalue->intValue();
	if(mv == 1){
	   return;
	}
    //A星搜索
	path = myastar->findPath(mapindex.x,mapindex.y,aimmapindex.x,aimmapindex.y,map);
	stepindex = 1;
	smallstepindex = 0;
}
开发者ID:Dashryder56,项目名称:book-code,代码行数:31,代码来源:MapScene.cpp

示例2: ccTouchesBegan

void MapScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint m_tBeginPos = touch->locationInView();	
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
	CCPoint playerpoint = gameplayer->getPosition();
	CCSize palyersize = gameplayer->getContentSize();
    CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	CCPoint mappoint = map->getPosition();
    //根据触摸点的位置判断人物移动方向
	if(m_tBeginPos.x < playerpoint.x - palyersize.width / 2 + mappoint.x){
	   hmove = -1;//左移
	}else if(m_tBeginPos.x > playerpoint.x + palyersize.width / 2 + mappoint.x){
	   hmove = 1;//右移
	}else{
	   hmove = 0;
	}
	if(m_tBeginPos.y > playerpoint.y + palyersize.height + mappoint.y){
	   vmove = 6;//上跳
	}else{
	   vmove = 0;
	}
}
开发者ID:uhealin,项目名称:asskicker,代码行数:25,代码来源:MapScene.cpp

示例3: CCDirectorGetWindowsSize

/**
 * 聚焦到某人身上,必须先设置场景代理
 *
 * 聚焦:
 *    1.假定人物位于屏幕中间
 *    2.消除地图滚动的偏移
 */
void
MCCamera::focus(MCRole *aRole)
{
    if (sceneDelegate_) {
        CCSize winSize = CCDirectorGetWindowsSize();
        MCScene *scene = sceneDelegate_->getScene();
        CCTMXTiledMap *map = sceneDelegate_->getScene()->getMap();
        CCSize sceneSize = scene->getSceneSize();
        CCPoint mapOffset = map->getPosition();
        CCPoint rolePosition = ccpSub(aRole->getEntity()->getPosition(), mapOffset);
        CCPoint expectedViewportOrigin = ccp(rolePosition.x - winSize.width / 2,
                                             rolePosition.y - winSize.height / 2);
        /* 清除偏移 */
        /* 基于地图 */
        float viewportLeft = expectedViewportOrigin.x;
        float viewportRight = expectedViewportOrigin.x + viewport_.size.width;
        float viewportTop = expectedViewportOrigin.y + viewport_.size.height;
        float viewportBottom = expectedViewportOrigin.y;
        
        if (sceneSize.width < winSize.width) {
            sceneSize.width = winSize.width;
        }
        if (sceneSize.height < winSize.height) {
            sceneSize.height = winSize.height;
        }
        
        if (viewportLeft < 0) {
            expectedViewportOrigin.x -= viewportLeft;
        } else if (viewportRight > sceneSize.width) {
            expectedViewportOrigin.x -= (viewportRight - sceneSize.width);
        }
        if (viewportTop > sceneSize.height) {
            expectedViewportOrigin.y -= (viewportTop - sceneSize.height);
        } else if (viewportBottom < 0) {
            expectedViewportOrigin.y -= viewportBottom;
        }
        
        viewport_.origin = expectedViewportOrigin;
        sceneDelegate_->moveSceneToLocation(ccpNeg(expectedViewportOrigin));
    }
}
开发者ID:edison9888,项目名称:__graduation_project,代码行数:48,代码来源:MCCamera.cpp


注:本文中的CCTMXTiledMap::getPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。