本文整理汇总了C++中CCTMXLayer类的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXLayer类的具体用法?C++ CCTMXLayer怎么用?C++ CCTMXLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCTMXLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getChildByTag
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;
}
示例2: CCSizeMake
void RoadScene::Event_1(){
CCTMXLayer * layer = map->layerNamed("entrance_covered");
layer->setVisible(false);
CCRPGTalkBox* box1 = CCRPGTalkBox::create(13, "dialog-box.png", "2_3.txt", 13, CCSizeMake(800, 200), 1,callfunc_selector(RoadScene::GoToNextStage),this,screenpos);
addChild(box1,9999,13);
box1->NextText();
}
示例3: initCostMap
void MyBattleMap::initCostMap() {
CCTMXLayer* layer = this->layerNamed("tiled");
CCSize size = this->getMapSize();
const char* str;
int cost = 0;
costMap = new int*[(int)size.width];
for(int i = 0; i < size.width; i++) {
costMap[i] = new int[(int)size.height];
}
for (int i=0; i<size.width; ++i) {
for (int j=0; j<size.height; ++j) {
str = ((CCString*) this->propertiesForGID(layer->tileGIDAt(ccp(i,j)))->objectForKey("cost"))->getCString();
costMap[i][j] = sscanf(str, "%d", &cost);
}
}
mybuildingMap = new CCObject**[(int)size.width+2];
for(int i = 0; i < size.width+2; i++) {
mybuildingMap[i] = new CCObject*[(int)size.height+2];
}
for (int i=0; i<size.width+2; ++i) {
for (int j=0; j<size.height+2; ++j) {
mybuildingMap[i][j] = NULL;
}
}
// layer->get
// if (Mathlib::inBound(int(tiled.x+0.5),this->getMapSize().width-1 , 0)&&Mathlib::inBound(int(tiled.y+0.5),this->getMapSize().height-1 , 0)) {
// //// CCLog("TransX:%f,transY:%f",ceil(tiled.x),ceil(tiled.y));
// layer->setTileGID(3,ccp(int(tiled.x+0.5),int(tiled.y+0.5)));
// }
}
示例4: getChildByTag
void MapScene::playermapvcollision(){
//主角与地图竖直(下)图素的碰撞检测
CCPoint playerpoint = gameplayer->getPosition();
CCSize palyersize = gameplayer->getContentSize();
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
int indexx,indexy;
CCTMXLayer* layer = map->layerNamed("logic");
//人物下边界
indexx = (playerpoint.x) / map->getTileSize().width;
indexy = map->getMapSize().height - (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 == 1){
if(vmove < 0){
vmove = 0;
hmove = 0;
playerpoint.y = (map->getMapSize().height - indexy) * map->getTileSize().height;
gameplayer->setPosition(playerpoint);
}
return;
}
}
vmove -= 0.2;
}
示例5: spriteMoveFinished
void Soko::spriteMoveFinished(CCNode *sender)
{
mpPlayer->mIsMoving = false;
int mapYSize = this->getTileMap()->getMapSize().height;
CCTMXLayer *pTMGround = this->getTileMap()->layerNamed("Ground");
// Change the boxes to show whether they are on a goal spot or not
// This code is a bit of a duplicate of the code that moves the boxes,
// but I don't want to do the update until the move completes
int GoalCount = 0;
int BoxCount = 0;
CCArray *pBoxes = this->getTileMap()->getChildren();
for(int i=0; i<pBoxes->count(); ++i)
{
CCSprite *pBox = (CCSprite *)pBoxes->objectAtIndex(i);
if (pBox->getTag() == 1)
{
// Need to actually count these as tile map has children other than
// just the boxes, such as the player and any effects I might add
++BoxCount;
int boxXCell = (pBox->getPosition().x-32) / 64;
int boxYCell = mapYSize - 1 - ((pBox->getPosition().y-32) / 64);
if (pTMGround->tileGIDAt( ccp(boxXCell, boxYCell) ) == 2)
{
// On floor
pBox->setTextureRect(CCRectMake(64,0,64,64));
}
else if (pTMGround->tileGIDAt( ccp(boxXCell, boxYCell) ) == 3)
{
// On goal
++GoalCount;
pBox->setTextureRect(CCRectMake(128,0,64,64));
}
}
}
ostringstream movesStr;
movesStr << "Moves: " << setw(4) << setfill('0') << mpPlayer->mMoveCount;
ostringstream pushesStr;
pushesStr << "Pushes: " << setw(4) << setfill('0') << mpPlayer->mPushCount;
// NB This crashed when I used TTFLabels
mpMovesLabel->setString(movesStr.str().c_str());
mpPushesLabel->setString(pushesStr.str().c_str());
if (GoalCount == BoxCount)
{
// Win!
mGameRunning = false;
// Fade label in and bounce its size a little
mpLevelCompleteLabel->runAction(CCFadeIn::actionWithDuration(0.5));
mpLevelCompleteLabel->runAction( CCSequence::actions(
CCScaleTo::actionWithDuration( (ccTime)0.25, 1.10 ),
CCScaleTo::actionWithDuration( (ccTime)0.25, 1.00 ), NULL) );
}
}
示例6: CCTMXLayer
// CCTMXLayer - init & alloc & dealloc
CCTMXLayer * CCTMXLayer::layerWithTilesetInfo(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXLayer *pRet = new CCTMXLayer();
if (pRet->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
pRet->autorelease();
return pRet;
}
return NULL;
}
示例7: tilesetForLayer
// private
CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
CCTMXLayer *layer = CCTMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->m_bOwnTiles = false;
layer->setupTiles();
return layer;
}
示例8: TileMapLayerPosToTileMapPos
CCSprite* CMGameMap::TileMapLayerPosToTileSprite( CCPoint TileMapLayerPos)
{
do
{
CCPoint TileMapPos = TileMapLayerPosToTileMapPos(TileMapLayerPos);
//获得地图的各个层
CCTMXLayer* pCloudLayer = layerNamed("cloud");
CC_BREAK_IF(pCloudLayer==NULL);
CCTMXLayer* pBlockLayer = layerNamed("block");
CC_BREAK_IF(pBlockLayer==NULL);
CCTMXLayer* pPipeLayer = layerNamed("pipe");
CC_BREAK_IF(pPipeLayer==NULL);
CCTMXLayer* pLandLayer = layerNamed("land");
CC_BREAK_IF(pLandLayer==NULL);
CCTMXLayer* pTrapLayer = layerNamed("trap");
CC_BREAK_IF(pTrapLayer==NULL);
CCTMXObjectGroup* pObjectLayer = objectGroupNamed("objects");
CC_BREAK_IF(pObjectLayer==NULL);
CCTMXLayer* pCoinLayer = layerNamed("coin");
CC_BREAK_IF(pCoinLayer==NULL);
CCTMXLayer* pFlagpoleLayer = layerNamed("flagpole");
CC_BREAK_IF(pFlagpoleLayer==NULL);
//若马里奥超过上边界
if(TileMapPos.y<0)return NULL;
CCSprite* pLandSprite = pLandLayer->tileAt(ccp(TileMapPos.x,TileMapPos.y));
if (pLandSprite!=NULL)
{
return pLandSprite;
}
CCSprite* pBlockSprite = pBlockLayer->tileAt(ccp(TileMapPos.x,TileMapPos.y));
if (pBlockSprite!=NULL)
{
//遍历砖块数组,如果砖块数组中未找到,则说明已被顶坏,返回空
CCObject *pObj = NULL;
CCARRAY_FOREACH(m_pArrayBlocks,pObj)
{
CMItemBlock* pItem = dynamic_cast<CMItemBlock*>(pObj);
CC_BREAK_IF(pItem==NULL);
CCPoint CurBlockWorldPos = (pBlockSprite->getPosition());
CCPoint TempBlockWorldPos = (pItem->getPosition());
//找到则返回砖块精灵
if (abs(CurBlockWorldPos.x==TempBlockWorldPos.x) &&
abs(CurBlockWorldPos.y==TempBlockWorldPos.y))
{
return pBlockSprite;
}
}
return NULL;
}
示例9: CCTMXLayer
NS_CC_BEGIN
// CCTMXLayer - init & alloc & dealloc
CCTMXLayer * CCTMXLayer::create(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXLayer *pRet = new CCTMXLayer();
if (pRet->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
pRet->autorelease();
return pRet;
}
return NULL;
}
示例10: 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.
}
示例11: NSAssert
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
{
NSAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
setContentSize(CGSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
NSAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
m_tMapSize = mapInfo->getMapSize();
m_tTileSize = mapInfo->getTileSize();
m_nMapOrientation = mapInfo->getOrientation();
setObjectGroups(mapInfo->getObjectGroups());
setProperties(mapInfo->getProperties());
CCX_SAFE_RELEASE(m_pTileProperties);
m_pTileProperties = mapInfo->getTileProperties();
CCX_SAFE_RETAIN(m_pTileProperties);
int idx = 0;
NSMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
if (layers && layers->count()>0)
{
CCTMXLayerInfo *layerInfo = NULL;
NSMutableArray<CCTMXLayerInfo*>::NSMutableArrayIterator it;
for (it = layers->begin(); it != layers->end(); ++it)
{
layerInfo = *it;
if (layerInfo && layerInfo->m_bVisible)
{
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild((CCNode*)child, idx, idx);
// update content size with the max size
CGSize childSize = child->getContentSize();
CGSize currentSize = this->getContentSize();
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
}
return true;
}
示例12: 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;
}
示例13: ccp
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)));
}
示例14:
// public
CCTMXLayer * CCTMXTiledMap::layerNamed(const char *layerName)
{
std::string sLayerName = layerName;
if (m_pChildren && m_pChildren->count()>0)
{
CCTMXLayer *layer;
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
layer = (CCTMXLayer*)(*it);
if (layer && layer->getLayerName() == sLayerName)
{
return layer;
}
}
}
// layer not found
return NULL;
}
示例15: CCAssert
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
{
CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
setContentSize(CCSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
if (! mapInfo)
{
return false;
}
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
m_tMapSize = mapInfo->getMapSize();
m_tTileSize = mapInfo->getTileSize();
m_nMapOrientation = mapInfo->getOrientation();
setObjectGroups(mapInfo->getObjectGroups());
setProperties(mapInfo->getProperties());
CC_SAFE_RELEASE(m_pTileProperties);
m_pTileProperties = mapInfo->getTileProperties();
CC_SAFE_RETAIN(m_pTileProperties);
int idx = 0;
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
if (layers && layers->count()>0)
{
if (NULL == m_pTMXLayers)
{
m_pTMXLayers = new CCDictionary<std::string, CCTMXLayer*>();
CCAssert(m_pTMXLayers, "Allocate memory failed!");
}
CCTMXLayerInfo *layerInfo = NULL;
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
for (it = layers->begin(); it != layers->end(); ++it)
{
layerInfo = *it;
if (layerInfo && layerInfo->m_bVisible)
{
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild((CCNode*)child, idx, idx);
// record the CCTMXLayer object by it's name
std::string layerName = child->getLayerName();
m_pTMXLayers->setObject(child, layerName);
// update content size with the max size
const CCSize& childSize = child->getContentSize();
CCSize currentSize = this->getContentSize();
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
}
return true;
}