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


C++ CCTMXTiledMap类代码示例

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


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

示例1: CCTMXTiledMap

NS_CC_BEGIN

	// implementation CCTMXTiledMap
	CCTMXTiledMap * CCTMXTiledMap::tiledMapWithTMXFile(const char *tmxFile)
{
	CCTMXTiledMap *pRet = new CCTMXTiledMap();
	if (pRet->initWithTMXFile(tmxFile))
	{
		pRet->autorelease();
		return pRet;
	}
	CC_SAFE_DELETE(pRet);
	return NULL;
}
开发者ID:blakey87,项目名称:cocos2d-x-2.1.1,代码行数:14,代码来源:CCTMXTiledMap.cpp

示例2: imply_set

void BattleMap::f_decide(int i, int j){		//通过新的选中tile对map进行重构。 use the set to decide.
	imply_set(ts_last,0);
	ts_last.clear();

	CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagMap);
	CCTMXLayer* layer = map->layerNamed("Battle");

	unsigned int gid = layer->tileGIDAt(ccp(i,j));

	draw_mouse_range(ccp(i,j));

	m_mou_cur = ccp(i,j);
	imply_set(ts_last,c_r);
	imply_set(cs_dis,c_b);			//blue is higher than red.

}
开发者ID:frankiefanstar,项目名称:cocotd,代码行数:16,代码来源:BattleMap.cpp

示例3: CCArray

bool RPGMapItemsMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height)
{
    if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height))
    {
        this->m_stringList = stringList;
        this->m_stringList->retain();
        
        this->m_db = db;
        
        this->m_itemsList = new CCArray();
        this->m_itemsList->init();
        
        CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString());
        mainBg->setPosition(CCPointZero);
        mainBg->setTag(kRPGMapItemsMenuLayerTagBg);
        this->addChild(mainBg);
        
        CCMenu *mainMenu = CCMenu::create();
        mainMenu->setTag(kRPGMapItemsMenuLayerTagMainMenu);
        mainMenu->setAnchorPoint(CCPointZero);
        mainMenu->setPosition(CCPointZero);
        this->addChild(mainMenu);
        
        CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapItemsMenuLayerTagMainMenuBack);
        if(!menuBack)
        {
            menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapItemsMenuLayer::onMenu));
            menuBack->setPosition(ccp(40, 600));
            menuBack->setTag(kRPGMapItemsMenuLayerTagMainMenuBack);
            menuBack->setScale(0.5);
            mainMenu->addChild(menuBack);
        }
        
        CCTableView *tableView = CCTableView::create(this, CCSizeMake(900, 570));
        tableView->setDirection(kCCScrollViewDirectionVertical);
        tableView->setPosition(ccp(80, 30));
        tableView->setDelegate(this);
        tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
        tableView->setTag(kRPGMapItemsMenuLayerTagItemListTable);
        this->addChild(tableView);
        
        this->loadItemsData();
        
        return true;
    }
    return false;
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:47,代码来源:RPGMapItemsMenuLayer.cpp

示例4: getChildByTag

void MapScene::playermaphcollision(){
    //主角与地图水平(左右)图素的碰撞检测
	CCPoint playerpoint = gameplayer->getPosition();
	CCSize palyersize = gameplayer->getContentSize();
	CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	int indexx,indexy;
	char mch[256];
	CCTMXLayer* layer = map->layerNamed("logic");
    //遍历图素块
	for(int playery = playerpoint.y - palyersize.height;playery <= playerpoint.y;playery ++){
	   //人物左边界
       indexx = (playerpoint.x - palyersize.width / 2) / map->getTileSize().width;
	   indexy = (playerpoint.y) / map->getTileSize().height;
	   CCPoint playerindex = ccp(indexx,indexy);
	   int tilegid = layer->tileGIDAt(playerindex);
	   if(tilegid > 0){
          //如果碰撞,设置主角位置
	      CCDictionary *tiledic = map->propertiesForGID(tilegid);
	      CCString *mvalue = (CCString *)tiledic->objectForKey("collion");
          int mv = mvalue->intValue();
	      if(mv == 2){
             hmove = 0;
		     playerpoint.x = (indexx + 1) * map->getTileSize().width + palyersize.width / 2;
		     gameplayer->setPosition(playerpoint);
	      }
		  return;
	   }
       //人物右边界
	   indexx = (playerpoint.x + palyersize.width / 2 - 1) / map->getTileSize().width;
	   indexy = (playerpoint.y) / map->getTileSize().height;
	   playerindex = ccp(indexx,indexy);
	   tilegid = layer->tileGIDAt(playerindex);
	   if(tilegid > 0){
          //如果碰撞,设置主角位置
          CCDictionary *tiledic = map->propertiesForGID(tilegid);
          CCString *mvalue = (CCString *)tiledic->objectForKey("collion");
          int mv = mvalue->intValue();
	      if(mv == 2){
             hmove = 0;
		     playerpoint.x = (indexx) * map->getTileSize().width - palyersize.width / 2;
		     gameplayer->setPosition(playerpoint);
	      }
		  return;
	   }
	}
}
开发者ID:uhealin,项目名称:asskicker,代码行数:46,代码来源:MapScene.cpp

示例5: initWithSpriteFrameName

void Tank::initTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
	initWithSpriteFrameName(tankTypeName);
	mTileMapInfo = tileMapInfo;

	//将坦克放入地图层中
	mTileMapInfo->getTileMap()->addChild(this);

	//缩放到合适大小
	CCTMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap();
	CCSize tileSize = tmxTileMap->getTileSize();
	CCSize tankSize = getContentSize();
	//比地图上砖块小一点
	setScale((tileSize.height * 2-4) / (tankSize.height));

	//初始化坦克的子弹
	mBullet = Bullet::createBulletWithTank(this);
}
开发者ID:Ju2ender,项目名称:tankwar,代码行数:18,代码来源:Tank.cpp

示例6: canPassedCOLROW

bool TileMap::canPassedCOLROW(cocos2d::CCPoint pos){
    CCLayer *layer = this->getLayer();
    CCTMXTiledMap *tileMap = dynamic_cast<CCTMXTiledMap*>(layer->getChildByTag(tilemap_tag));
    //获得block层
    CCTMXLayer *block = tileMap->layerNamed("block");
    //获得砖块(根据某个位置)
    int tileGID = block->tileGIDAt(pos);
    if (tileGID) {
        CCDictionary *properties = tileMap->propertiesForGID(tileGID);
        if (properties) {
            const CCString *collion = properties->valueForKey("blockTiled");
            if (collion&&collion->compare("1")) {
                return true;
            }
        }
    }
    return true;
}
开发者ID:GITHZZ,项目名称:Cocos2dx_AI,代码行数:18,代码来源:TileMap.cpp

示例7: addBackground

void MyScene::addBackground(){
	CCTMXTiledMap* pTmap = CCTMXTiledMap::create("TileMaps/TestDesert.tmx");
	pTmap->setName("Tmap");
	backgroundNode = CCParallaxNode::create();
	backgroundNode->setName("Background");
	backgroundNode->addChild(pTmap, 1, ccp(1.0f, 1.0f), ccp(0, 0));
	this->addChild(backgroundNode, 0);

	CCTMXObjectGroup* objects = pTmap->objectGroupNamed("Objects");
	ValueMap& spawnPoint = objects->getObject("SpawnPoint");
	CCTMXLayer* metaInfo = pTmap->getLayer("MetaInfo");
	metaInfo->setVisible(false);

	//create a dragon on "SpawnPoint"
	int x = spawnPoint["x"].asInt();
	int y = spawnPoint["y"].asInt();

	this->createDragon(CCPoint(ccp(x, y)));
}
开发者ID:yooasd11,项目名称:summerproject,代码行数:19,代码来源:MyScene.cpp

示例8: doMoving

bool RPGMapSceneLayer::doMoving(cocos2d::CCPoint targetPoint)
{
    //这里的逻辑跟RPGMapNPCRoleSprite::autoMove类似
    
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
    CCTMXObjectGroup *obstaclesObjects = bgMap->objectGroupNamed("obstacles");
    
    targetPoint = ccpAdd(player->getPosition(), targetPoint);
    
    //地图上的障碍物
    for (int i = 0; i < obstaclesObjects->getObjects()->count(); i++)
    {
        CCDictionary *obstaclesObject = (CCDictionary*)obstaclesObjects->getObjects()->objectAtIndex(i);
        const CCString *x = obstaclesObject->valueForKey("x");
        const CCString *y = obstaclesObject->valueForKey("y");
        const CCString *width = obstaclesObject->valueForKey("width");
        const CCString *height = obstaclesObject->valueForKey("height");
        
        CCRect obstaclesRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString()));
        
        if(obstaclesRect.containsPoint(targetPoint))
            return false;
    }
    
    //NPC或Player
    for (int i = 0; i < bgMap->getChildren()->count(); i++)
    {
        CCObject *item = bgMap->getChildren()->objectAtIndex(i);
        if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
        {
            //如果为非player的对象才会执行里面的判断
            if(item != player)
            {
                if(((RPGMapRoleSprite*)item)->boundingBox().containsPoint(targetPoint))
                    return false;
            }
        }
    }
    
    return true;
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:42,代码来源:RPGMapSceneLayer.cpp

示例9: Rect

void MyScene::createDragon(CCPoint dragonPosition){
	CCTexture2D* texture = CCDirector::getInstance()->getTextureCache()->addImage("Animations/dragon_animation.png");
	CCAnimation* animation = Animation::create();
	animation->setDelayPerUnit(0.05f);
	for (int i = 0; i < 6; ++i){
		int index = 1 % 4;
		int rowIndex = i / 4;
		animation->addSpriteFrameWithTexture(texture, Rect(index * 130, rowIndex * 140, 130, 140));
	}

	CCSprite* pDragon = Sprite::createWithTexture(texture, Rect(0, 0, 130, 140));
	pDragon->setPosition(dragonPosition);
	pDragon->setFlippedX(true);
	pDragon->setScale(0.5);
	pDragon->setName("Dragon");
	CCTMXTiledMap* pTmap = (CCTMXTiledMap*)backgroundNode->getChildByName("Tmap");
	pTmap->addChild(pDragon, 3, 15);


	CCSprite* fireAim = CCSprite::create("line.PNG");
	fireAim->setPosition(pDragon->getContentSize().width / 2, pDragon->getContentSize().height / 3);
	fireAim->setName("Aim");
	fireAim->setScale(0.3f);
	fireAim->setAnchorPoint(ccp(-0.5f, 0.5f));
	pDragon->addChild(fireAim, 2);

	CCSprite* bullet = CCSprite::create("bullet.PNG");
	bullet->setName("Bullet");
	bullet->setVisible(false);
	bullet->setScale(0.3f);
	bullet->setPosition(ccp(5.0f, 5.0f));
	this->addChild(bullet);

	Animate* animate = Animate::create(animation);
	RepeatForever* rep = RepeatForever::create(animate);
	pDragon->runAction(rep);

	pJYPlayerDragon = new JYPlayer(pDragon);
	JYArm* pJYArmBullet = new JYArm(bullet);
	pJYArmBullet->setName("JYBullet");
	pJYPlayerDragon->addChild(pJYArmBullet);
}
开发者ID:yooasd11,项目名称:summerproject,代码行数:42,代码来源:MyScene.cpp

示例10: init

bool RPGDialogLayer::init(string titleStr, string menuOKStr, int menuItemOKTag, float width, float height, CCObject* target, SEL_MenuHandler seletor)
{
    if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height))
    {
        this->initCommons(titleStr);
        
        CCTMXTiledMap *mainBg = (CCTMXTiledMap*)this->getChildByTag(kRPGDialogLayerBg);
        CCMenu *menu = (CCMenu*)mainBg->getChildByTag(kRPGDialogLayerBgMenu);
        
        CCLabelTTF *menuOKLab = CCLabelTTF::create(OzgCCUtility::generalString(CCString::create(menuOKStr)->getCString()).c_str(), "Arial", 20, CCSizeMake(120, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        menuOKLab->setColor(ccc3(160, 160, 160));
        CCMenuItemLabel *menuOK = CCMenuItemLabel::create(menuOKLab, target, seletor);
        menuOK->setTag(menuItemOKTag);
        menuOK->setPosition(ccp(190, 60));
        menu->addChild(menuOK);
        
        return true;
    }
    return false;
}
开发者ID:aboduo,项目名称:OzgGameRPG,代码行数:20,代码来源:RPGDialogLayer.cpp

示例11: 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

示例12: getChildByTag

//坐标与地图位置的转换
CCPoint MapScene::convertto2d(float x,float y){
	CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	int mapWidth = map->getMapSize().width * map->getTileSize().width;
	int mapHeight = map->getMapSize().height * map->getTileSize().height;
	double distanse;
	double sin1;
	double sin11;
	double sin22;
	double cos11;
	double cos1;
	int d2x;
	int d2y;
	double mystatic5 = sqrt(5.0);//«Û∏˘∫≈5
	double mystatic = 16 * mystatic5;//–°ÕºøÈ¿‚≥§
	//char mch[256];
	if(x > mapWidth/2){
	   distanse = sqrt((x - mapWidth/2) * (x - mapWidth/2) + (mapHeight - y) * (mapHeight - y));
	   sin1 = (mapHeight - y)/distanse;
	   cos1 = (x - mapWidth/2)/distanse;
	   sin11 = (sin1 * 2 - cos1) / mystatic5;
	   cos11 = (sin1 + cos1 * 2) / mystatic5;
	   d2y = distanse * 5 / 4 * sin11 / mystatic;
	   sin22 = (2 * sin1 + cos1) / mystatic5;
	   d2x = distanse * 5 / 4 * sin22 / mystatic;
	   return ccp(d2x,d2y);
	}else{
	   distanse = sqrt((mapWidth/2 - x) * (mapWidth/2 - x) + (mapHeight - y) * (mapHeight - y));
	   sin1 = (mapHeight - y)/distanse;
	   cos1 = (mapWidth/2 - x)/distanse;
	   sin11 = (sin1 * 2 - cos1) / mystatic5;
	   cos11 = (sin1 + cos1 * 2) / mystatic5;
	   d2x = distanse * 5 / 4 * sin11 / mystatic;
	   //sin22 = 4.0 * cos11 / 5 + 3.0 * sin11 / 5;
	   sin22 = (2 * sin1 + cos1) / mystatic5;
	   d2y = distanse * 5 / 4 * sin22 / mystatic;
	   return ccp(d2x,d2y);
	}
}
开发者ID:Dashryder56,项目名称:book-code,代码行数:39,代码来源:MapScene.cpp

示例13: showMenu

void RPGBattleMenu::showMenu()
{
    CCTMXTiledMap *bgLayer = (CCTMXTiledMap*)this->m_parentNode->getChildByTag(kRPGBattleMenuTagBg);
    bgLayer->setVisible(true);
    
    CCLabelTTF *nameLab = (CCLabelTTF*)this->m_parentNode->getChildByTag(kRPGBattleMenuTagNameLab);
    nameLab->setVisible(true);
    
    CCSprite *separate = (CCSprite*)this->m_parentNode->getChildByTag(kRPGBattleMenuTagSeparate);
    separate->setVisible(true);
    
    CCMenuItem *menuAttack = (CCMenuItem*)this->getChildByTag(kRPGBattleMenuTagAttack);
    menuAttack->setVisible(true);
    
    CCMenuItem *menuSkill = (CCMenuItem*)this->getChildByTag(kRPGBattleMenuTagSkill);
    menuSkill->setVisible(true);
    
    CCMenuItem *menuItems = (CCMenuItem*)this->getChildByTag(kRPGBattleMenuTagItems);
    menuItems->setVisible(true);
    
    CCMenuItem *menuEscape = (CCMenuItem*)this->getChildByTag(kRPGBattleMenuTagEscape);
    menuEscape->setVisible(true);
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:23,代码来源:RPGBattleMenu.cpp

示例14: initWithSpriteFrameName

void Tank::initTankWithTankType(const char *tankTypeName, TileMapInfo *tileMapInfo) {
    
    initWithSpriteFrameName(tankTypeName);
    mTileMapInfo = tileMapInfo;
    
    mTileMapInfo->getTileMap()->addChild(this);
    CCTMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap(); 
    CCSize tileSize = tmxTileMap->getTileSize();
    
    CCSize tankSize = getContentSize();
    
    printf("cont: %f,%f\n",tankSize.width,tankSize.height);
   // CCRect rect = this->boundingBox();
   //  printf("rect_pos: %f, %f",rect.getMinX(),rect.getMinY());
    
    setScale((tileSize.height * 2-4) / (tankSize.height));
    
    
    // CCRect rect = this->boundingBox();
    // printf("rect_pos: %f, %f",rect.getMinX(),rect.getMinY());
    
   mBullet = Bullet::createBulletWithTank(this);
}
开发者ID:k8802810,项目名称:cocos2dx_tank,代码行数:23,代码来源:Tank.cpp

示例15: enabledControl

void RPGMapSceneLayer::enabledControl(bool enabled)
{
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
    
    OzgJoystickLayer *joystick = (OzgJoystickLayer*)this->getChildByTag(kRPGMapSceneLayerTagJoystick);
    
    if(enabled)
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
        
        joystick->active();
        mainMenu->setVisible(true);
        
    }
    else
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
        
        joystick->inactive();
        mainMenu->setVisible(false);
        
    }
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:24,代码来源:RPGMapSceneLayer.cpp


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