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


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

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


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

示例1: ccTouchEnded

void RPGMapSceneLayer::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
    if(this->m_touchedDialogNPC)
    {
        CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
        
        CCPoint point = touch->getLocation();
        point = bgMap->convertToNodeSpace(point);
        
        if(this->m_touchedDialogNPC->boundingBox().containsPoint(point))
        {
            this->m_touchedDialogNPC->stopAutoMove(); //暂时停止自动移动
            
            this->enabledControl(false);
            
            string content = this->m_touchedDialogNPC->m_content->getCString();
            RPGMapDialogLayer *dialogLayer = RPGMapDialogLayer::create(this->m_stringList, &this->m_db, this->m_touchedDialogNPC);
            this->addChild(dialogLayer);
            
            CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
            mainMenu->setVisible(false);
            
            //player和NPC互相对着
            RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
            switch (this->m_dialogDirection)
            {
                case kRPGMapSceneLayerDialogDirectionUp:
                {
                    player->setDirection(kRPGMapRoleSpriteDirectionDown);
                    this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionUp);
                }
                    break;
                case kRPGMapSceneLayerDialogDirectionDown:
                {
                    player->setDirection(kRPGMapRoleSpriteDirectionUp);
                    this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionDown);
                }
                    break;
                case kRPGMapSceneLayerDialogDirectionLeft:
                {
                    player->setDirection(kRPGMapRoleSpriteDirectionRight);
                    this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionLeft);
                }
                    break;
                case kRPGMapSceneLayerDialogDirectionRight:
                {
                    player->setDirection(kRPGMapRoleSpriteDirectionLeft);
                    this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionRight);
                }
                    break;
                default:
                    break;
            }
            
        }
    }
    
    this->m_touchedDialogNPC = NULL;
    this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionNone;
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:60,代码来源:RPGMapSceneLayer.cpp

示例2: ccTouchBegan

bool RPGMapSceneLayer::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
    
    //循环判断点击了哪一个NPC,如果有点中则m_isTouchedNPC为true
    for (int i = 0; i < bgMap->getChildren()->count(); i++)
    {
        CCObject *item = bgMap->getChildren()->objectAtIndex(i);
        if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
        {
            RPGMapNPCRoleSprite *npc = (RPGMapNPCRoleSprite*)item;
            if(npc->m_type == kRPGMapRoleSpriteTypeNPC)
            {
                //判断player是否存在该NPC的四个方向(距离为一格),存在则为true
                bool exist = false;
                
                if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(0, GAME_TMX_ROLE_HEIGHT))))
                {
                    //上
                    exist = true;
                    this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionUp;
                }
                else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(0, -GAME_TMX_ROLE_HEIGHT))))
                {
                    //下
                    exist = true;
                    this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionDown;
                }
                else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(-GAME_TMX_ROLE_WIDTH, 0))))
                {
                    //左
                    exist = true;
                    this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionLeft;
                }
                else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(GAME_TMX_ROLE_WIDTH, 0))))
                {
                    //右
                    exist = true;
                    this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionRight;
                }
                
                if(exist)
                {
                    CCPoint point = touch->getLocation();
                    point = bgMap->convertToNodeSpace(point);
                    if(npc->boundingBox().containsPoint(point))
                    {
                        this->m_touchedDialogNPC = npc;
                        break;
                    }
                }
                
            }
        }
    }
    
    //如果是点中了NPC则进入ccTouchEnded的处理
    if(this->m_touchedDialogNPC)
        return true;
    else
    {
        //传入到摇杆的事件处理
        CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
        mainMenu->setVisible(false);
        return false;
    }
    
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:69,代码来源:RPGMapSceneLayer.cpp


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