本文整理汇总了C++中TMXObjectGroup::getObjects方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXObjectGroup::getObjects方法的具体用法?C++ TMXObjectGroup::getObjects怎么用?C++ TMXObjectGroup::getObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXObjectGroup
的用法示例。
在下文中一共展示了TMXObjectGroup::getObjects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: importGroundData
void GameLayer::importGroundData(cocos2d::TMXTiledMap* data)
{
TMXObjectGroup *objects = m_pTiledMap->getObjectGroup("Grounds");
const ValueVector _objects = objects->getObjects();
if (!_objects.empty())
{
for (const auto& v : _objects)
{
const ValueMap& dict = v.asValueMap();
if (dict.find("name") != dict.end())
{
if (dict.at("name").asString() == "Ground" || dict.at("name").asString() == "Box")
{
Size boxSize(dict.at("width").asFloat(), dict.at("height").asFloat());
auto ground = Ground::create();
if(dict.find("rotation") != dict.end())
ground->initPhysics(boxSize, Point(dict.at("x").asFloat(), dict.at("y").asFloat()), dict.at("rotation").asInt());
else
ground->initPhysics(boxSize, Point(dict.at("x").asFloat(), dict.at("y").asFloat()), 0);
this->addChild(ground);
}
}
}
}
}
示例2: _initTower
void BattleLayer::_initTower(){
TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
TMXObjectGroup *towerObjectData = tiledMap->getObjectGroup("tower");
auto &towersData = towerObjectData->getObjects();
for (auto &towerDataItem : towersData){
ValueMap &towerData = towerDataItem.asValueMap();
// CCLOG("%s, %s", towerData["side"].asString().c_str(), towerData["type"].asString().c_str());
if (towerData["side"].asString() == "player"){
if (towerData["type"].asString() == "king"){
// _playerKingTower = Tower::createTower(TowerType::King, Side::Player, this);
playerKingTower = createTower(TowerType::King, Side::Player, this);
playerKingTower->setPosition(_battleMapSize.width / 2, 0);
_battleMap->addChild(playerKingTower, getBattleElementZOrderOnBattleMap(playerKingTower));
playerTowers.push_back(playerKingTower);
}else {
if (towerData["road"].asString() == "left"){
// _playerDefendLeftTower = Tower::createTower(TowerType::Defend, Side::Player, this);
playerDefendLeftTower = createTower(TowerType::Defend, Side::Player, this);
playerDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 5);
_battleMap->addChild(playerDefendLeftTower, getBattleElementZOrderOnBattleMap(playerDefendLeftTower));
playerTowers.push_back(playerDefendLeftTower);
}
if (towerData["road"].asString() == "right"){
// _playerDefendRightTower = Tower::createTower(TowerType::Defend, Side::Player, this);
playerDefendRightTower = createTower(TowerType::Defend, Side::Player, this);
playerDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 5);
_battleMap->addChild(playerDefendRightTower, getBattleElementZOrderOnBattleMap(playerDefendRightTower));
playerTowers.push_back(playerDefendRightTower);
}
}
}else {
if (towerData["type"].asString() == "king"){
// _npcKingTower = Tower::createTower(TowerType::King, Side::NPC, this);
npcKingTower = createTower(TowerType::King, Side::NPC, this);
npcKingTower->setPosition(_battleMapSize.width / 2, _battleTileSize.height * 26);
_battleMap->addChild(npcKingTower, getBattleElementZOrderOnBattleMap(npcKingTower));
npcTowers.push_back(npcKingTower);
}else {
if (towerData["road"].asString() == "left"){
// _npcDefendLeftTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
npcDefendLeftTower = createTower(TowerType::Defend, Side::NPC, this);
npcDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 23);
_battleMap->addChild(npcDefendLeftTower, getBattleElementZOrderOnBattleMap(npcDefendLeftTower));
npcTowers.push_back(npcDefendLeftTower);
}
if (towerData["road"].asString() == "right"){
// _npcDefendRightTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
npcDefendRightTower = createTower(TowerType::Defend, Side::NPC, this);
npcDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 23);
_battleMap->addChild(npcDefendRightTower, getBattleElementZOrderOnBattleMap(npcDefendRightTower));
npcTowers.push_back(npcDefendRightTower);
}
}
}
}
}
示例3: onTouchEnded
void HelloWorld::onTouchEnded(Touch* touch, Event* event){
TMXObjectGroup* objGroup = tiledMap->getObjectGroup("Obj1");
ValueVector vv = objGroup->getObjects();
auto o1 = objGroup->getObject("o1");
int xxx = o1.at("x").asInt();
int aa = o1.at("aa").asInt();
log("xxxx->%d,aa->%d", xxx,aa);
}
示例4: init
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
// Add sounds/effect
SimpleAudioEngine::getInstance()->preloadEffect("error.mp3");
SimpleAudioEngine::getInstance()->preloadEffect("item.mp3");
SimpleAudioEngine::getInstance()->preloadEffect("step.mp3");
SimpleAudioEngine::getInstance()->preloadEffect("wade.mp3");
SimpleAudioEngine::getInstance()->playBackgroundMusic("background.mp3");
SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.1);
// Load the tile map
std::string file = "01.tmx";
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
_tileMap = TMXTiledMap::createWithXML(str->getCString(),"");
_background = _tileMap->layerNamed("Background");
_foreground = _tileMap->layerNamed("Foreground01");
_layer01 = _tileMap->layerNamed("Layer01");
_layer02 = _tileMap->layerNamed("Layer02");
_layer03 = _tileMap->layerNamed("Layer03");
_cross = _tileMap->layerNamed("CanCross01");
_cross->setVisible(false);
_blockage = _tileMap->layerNamed("Blockage01");
_blockage->setVisible(false);
addChild(_tileMap, -1);
// Position of the player
TMXObjectGroup *objects = _tileMap->getObjectGroup("Object-Player");
CCASSERT(NULL != objects, "'Object-Player' object group not found");
auto playerShowUpPoint = objects->getObject("PlayerShowUpPoint");
CCASSERT(!playerShowUpPoint.empty(), "PlayerShowUpPoint object not found");
int x = playerShowUpPoint["x"].asInt();
int y = playerShowUpPoint["y"].asInt();
_player = Sprite::create("029.png");
_player->setPosition(x + _tileMap->getTileSize().width / 2, y + _tileMap->getTileSize().height / 2);
_player->setScale(0.5);
addChild(_player);
setViewPointCenter(_player->getPosition());
// Position of the enemy
for (auto& eSpawnPoint: objects->getObjects()){
ValueMap& dict = eSpawnPoint.asValueMap();
if(dict["Enemy"].asInt() == 1){
x = dict["x"].asInt();
y = dict["y"].asInt();
this->addEnemyAtPos(Point(x, y));
}
}
// Event listener touch
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [&](Touch *touch, Event *unused_event)->bool {return true;};
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_numCollected = 0;
_mode = 0;
this->schedule(schedule_selector(HelloWorld::testCollisions));
return true;
}
示例5: initMap
void MapAnalysis::initMap(char* levelName)
{
GameManager* gameManager = GameManager::getInstance();
//¶ÁÈ¡TiledµØͼ×ÊÔ´
TMXTiledMap* tiledMap = TMXTiledMap::create(levelName);
gameManager->gameLayer->addChild(tiledMap, -1);
//todo--ÊӲ¾°£¬´Ë´¦ÐÞ¸Ä!TODO!ÔƲÊ
Sprite* could1 = Sprite::create("Items/cloud1.png");
could1->setPosition(500, 500);
gameManager->bkLayer->addChild(could1);
Sprite* could2 = Sprite::create("Items/cloud2.png");
could2->setPosition(900, 700);
gameManager->bkLayer->addChild(could2);
Sprite* could3 = Sprite::create("Items/cloud3.png");
could3->setPosition(1400, 450);
gameManager->bkLayer->addChild(could3);
Sprite* could4 = Sprite::create("Items/cloud1.png");
could4->setPosition(1400 + 500, 500);
gameManager->bkLayer->addChild(could4);
Sprite* could5 = Sprite::create("Items/cloud2.png");
could5->setPosition(1400 + 700, 700);
gameManager->bkLayer->addChild(could5);
Sprite* could6 = Sprite::create("Items/cloud3.png");
could6->setPosition(1400 + 1400, 450);
gameManager->bkLayer->addChild(could6);
//BrickLayer µØ°å Spikes ·æ´Ì
TMXObjectGroup* brickLayer = tiledMap->getObjectGroup("BrickLayer");
ValueVector bricks = brickLayer->getObjects();
for (int i = 0; i < bricks.size(); i++)
{
ValueMap brick = bricks.at(i).asValueMap();
float w = brick.at("width").asFloat();
float h = brick.at("height").asFloat();
float x = brick.at("x").asFloat() + w/2.0f;
float y = brick.at("y").asFloat() + h/2.0f;
if (brick.at("name").asString() == "Brick")//̨½×
{
Brick* b = Brick::create(x, y, w, h);
gameManager->gameLayer->addChild(b);
}
else if (brick.at("name").asString() == "Wall")//ǽ
{
Wall* wa = Wall::create(x, y, w, h);
gameManager->gameLayer->addChild(wa);
}
else if (brick.at("name").asString() == "Spikes")//·æ´Ì
{
Spikes* sk = Spikes::create(x, y, w, h);
gameManager->gameLayer->addChild(sk);
}
else if (brick.at("name").asString() == "DeadRoof")//ËÀÍǫ̈½×
{
DeadRoof* dr = DeadRoof::create(x, y, w, h);
gameManager->gameLayer->addChild(dr);
}
}
//CoinLayer ½ð±Ò
TMXObjectGroup* coinLayer = tiledMap->getObjectGroup("CoinLayer");
ValueVector coins = coinLayer->getObjects();
for (int i = 0; i < coins.size(); i++)
{
ValueMap coin = coins.at(i).asValueMap();
float w = SD_FLOAT("coin_float_width");
float h = SD_FLOAT("coin_float_height");
float x = coin.at("x").asFloat() + w / 2.0f;
float y = coin.at("y").asFloat() + h / 2.0f;
Coin* c = Coin::create(x, y, w, h);
gameManager->thingLayer->addChild(c);
}
//MonsterLayer ¹ÖÎï
TMXObjectGroup* monsterLayer = tiledMap->getObjectGroup("MonsterLayer");
ValueVector monsters = monsterLayer->getObjects();
for (int i = 0; i < monsters.size(); i++)
{
ValueMap monster = monsters.at(i).asValueMap();
//MonsterEx ÈËÐ͹ÖÎï
if (monster.at("name").asString() == "MonsterEx")
{
float w = SD_FLOAT("monster_float_width");
float h = SD_FLOAT("monster_float_height");
float x = monster.at("x").asFloat() + w / 2.0f;
float y = monster.at("y").asFloat() + h / 2.0f;
MonsterEx* m = MonsterEx::create(x, y, w, h);
gameManager->monsterLayer->addChild(m);
}
//FlyingSlime ·ÉÐÐÊ·À³Ä·
if (monster.at("name").asString() == "FlyingSlime")
{
float w = SD_FLOAT("flyingslime_float_width");
float h = SD_FLOAT("flyingslime_float_height");
float x = monster.at("x").asFloat() + w / 2.0f;
float y = monster.at("y").asFloat() + h / 2.0f;
FlyingSlime* f = FlyingSlime::create(x, y, w, h);
gameManager->monsterLayer->addChild(f);
//.........这里部分代码省略.........
示例6: startElement
//.........这里部分代码省略.........
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
// The value for "type" was blank or not a valid class name
// Create an instance of TMXObjectInfo to store the object and its properties
ValueMap dict;
// Parse everything automatically
const char* keys[] = {"name", "type", "width", "height", "gid"};
for (const auto& key : keys)
{
Value value = attributeDict[key];
dict[key] = value;
}
// But X and Y since they need special treatment
// X
int x = attributeDict["x"].asInt();
// Y
int y = attributeDict["y"].asInt();
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt());
p = CC_POINT_PIXELS_TO_POINTS(p);
dict["x"] = Value(p.x);
dict["y"] = Value(p.y);
int width = attributeDict["width"].asInt();
int height = attributeDict["height"].asInt();
Size s(width, height);
s = CC_SIZE_PIXELS_TO_POINTS(s);
dict["width"] = Value(s.width);
dict["height"] = Value(s.height);
// Add the object to the objectGroup
objectGroup->getObjects().push_back(Value(dict));
// The parent element is now "object"
tmxMapInfo->setParentElement(TMXPropertyObject);
}
else if (elementName == "property")
{
if ( tmxMapInfo->getParentElement() == TMXPropertyNone )
{
CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
attributeDict["name"].asString().c_str(), attributeDict["value"].asString().c_str() );
}
else if ( tmxMapInfo->getParentElement() == TMXPropertyMap )
{
// The parent element is the map
Value value = attributeDict["value"];
std::string key = attributeDict["name"].asString();
tmxMapInfo->getProperties().insert(std::make_pair(key, value));
}
else if ( tmxMapInfo->getParentElement() == TMXPropertyLayer )
{
// The parent element is the last layer
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
Value value = attributeDict["value"];
std::string key = attributeDict["name"].asString();
// Add the property to the layer
layer->getProperties().insert(std::make_pair(key, value));
}
else if ( tmxMapInfo->getParentElement() == TMXPropertyObjectGroup )
{
// The parent element is the last object group
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
Value value = attributeDict["value"];
示例7: loadMap
bool GameMap::loadMap(const int& level)
{
string fileName = StringUtils::format("map/map_%03d.tmx", level);
TMXTiledMap* map = TMXTiledMap::create(fileName);
m_map = map;
float scale = 1 / Director::getInstance()->getContentScaleFactor();
//GridPos
TMXObjectGroup* group = map->getObjectGroup("TowerPos");
ValueVector vec = group->getObjects();
m_gridPos.clear();
m_gridPos.resize(vec.size());
if (!vec.empty())
{
int i = 0;
for (const auto& v : vec)
{
const ValueMap& dict = v.asValueMap();
m_gridPos[i] = new GridPos(
i,
Rect(dict.at("x").asFloat(),
dict.at("y").asFloat(),
dict.at("width").asFloat(),
dict.at("height").asFloat()));
i++;
}
}
//计算临近的塔的ID
float h = group->getProperty("TowerPosHeight").asFloat() *scale;
float w = group->getProperty("TowerPosWidth").asFloat() *scale;
float dis = (h + 2)*(h + 2) + (w + 2)*(w + 2);
vector<int> GridPosID;
for (auto t1 : m_gridPos)
{
GridPosID.clear();
Point pos = t1->getPos();
for (auto t2 : m_gridPos)
{
if (t1 != t2 && pos.distanceSquared(t2->getPos())<=dis)
{
GridPosID.push_back(t2->ID);
}
}
int around[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
for (auto tid : GridPosID)
{
Rect rect = m_gridPos[tid]->getRect();
if (rect.containsPoint( Point(pos.x , pos.y + h )))around[North] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y + h )))around[NorthWest] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y )))around[West] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y - h )))around[SouthWest] = tid;
else if (rect.containsPoint( Point(pos.x , pos.y - h )))around[South] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y - h )))around[SouthEast] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y )))around[East] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y + h )))around[NorthEast] = tid;
}
t1->setAroundGridPosID(around);
}
//MonsterPath
group = map->getObjectGroup("Path");
vec = group->getObjects();
MonsterPath.clear();
if (!vec.empty())
{
vector<Point> posvec;
for (const auto& var : vec)
{
posvec.clear();
const ValueMap& dict = var.asValueMap();
const ValueVector& vec2 = dict.at("polylinePoints").asValueVector();
Point pos = Point(dict.at("x").asFloat(), dict.at("y").asFloat());
for (const auto& v : vec2)
{
const ValueMap& dict = v.asValueMap();
posvec.push_back(Point(pos.x + dict.at("x").asFloat()*scale, pos.y - dict.at("y").asFloat()*scale));
//posvec.push_back(Point(pos.x + dict.at("x").asFloat(), pos.y - dict.at("y").asFloat()));
}
MonsterPath.push_back(MapPath(dict.at("LoopTo").asInt(), posvec));
}
}
//WaveData
int waveCount= map->getProperty("WaveCount").asInt();
std::stringstream ss;
string propertyName;
WaveList.clear();
for (int i = 1; i <= waveCount; i++)
{
propertyName = StringUtils::format("Wave%03d", i);
group = map->getObjectGroup(propertyName);
CCASSERT(group != nullptr, string("propertyName :" + propertyName +" NOT found").c_str());
Wave wave;
wave.WaveTime = group->getProperty("waveTime").asInt();
//.........这里部分代码省略.........
示例8: parseMap
void DebugMap::parseMap( cocos2d::TMXTiledMap* tmap ){
TMXObjectGroup* wall = tmap->getObjectGroup("linewall");
Size mapSize = tmap->getContentSize();
tilesLen = tmap->getMapSize();
tilesSize= tmap->getTileSize()/2;
CCLOG("parseMap %f %f", D::mapSize.width, D::mapSize.height );
for( int i=0; i<tilesLen.height+1; i++ ) this->drawLine( Vec2( 0, i*(tilesSize.height)), Vec2( mapSize.width, i*(tilesSize.height) ), Color4F::BLUE );
for( int j=0; j<tilesLen.width+1; j++ ) this->drawLine( Vec2( j*(tilesSize.width), 0 ), Vec2( j*(tilesSize.width), mapSize.height ), Color4F::BLUE );
// CCLOG(" Line... %f, %f", tmap->getMapSize().width, tmap->getMapSize().height ); // 갯수
// CCLOG(" Line... %f, %f", tmap->getTileSize().width, tmap->getTileSize().height ); // 크기
DrawNode* wallNode = DrawNode::create();
this->addChild( wallNode );
int lineCount = 0;
for( auto obj : wall->getObjects())
{
bool first = true;
Vec2 prevPoint;
auto xx = obj.asValueMap()["x"].asFloat();
auto yy = obj.asValueMap()["y"].asFloat();
// 벽 생성 및 위치
for( auto value : obj.asValueMap() )
{
if( value.first == "polylinePoints"){
wallSeg.push_back( *new std::vector<Vec2> );
auto vec = value.second.asValueVector();
CCLOG("catch Line %d", lineCount );
first = true;
for( auto &p : vec ){
Vec2 point = Vec2( ( p.asValueMap().at("x").asFloat()*.5 ) + xx, -( p.asValueMap().at("y").asFloat()*.5 ) + yy );
if( first == false ){
wallNode->drawSegment( prevPoint, point, 3.0f, Color4F::WHITE );
}
wallSeg[lineCount].push_back(point);
prevPoint = point;
first = false;
}//for
CCLOG( "(%d) line length is %lu", lineCount, wallSeg[lineCount].size());
lineCount += 1;
}//if
}//for
}
parentMap.reserve(100);
getFastDistance( 8,0, 6,8 );
}
示例9: initActor
void GameMap::initActor()
{
TMXObjectGroup* group = this->objectGroupNamed("actor");
const ValueVector &objects = group->getObjects();
for (ValueVector::const_iterator it=objects.begin(); it!=objects.end(); it++)
{
const ValueMap &dict = (*it).asValueMap();
int x = dict.at("x").asInt();
int y = dict.at("y").asInt();
Vec2 pos = Vec2(x, y);
std::string texture = dict.at("texture").asString();
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(texture+".plist");
if (dict.at("enemy").asInt() == 0){
auto actor = ActorSprite::MyCreateInit(texture);
//初始化属性值
actor->atk = dict.at("atk").asInt();
actor->Tag = dict.at("tag").asInt();
actor->life = dict.at("life").asInt();
actor->range = dict.at("range").asInt();
//增加了属性
actor->atkrange = dict.at("atkrange").asInt();
//
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(ActorSprite::onTouchBegan, actor);
listener->onTouchEnded = CC_CALLBACK_2(ActorSprite::onTouchEnded, actor);
listener->setSwallowTouches(true);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, actor);
//-----------------------改了,添加监听
actor->setPosition(pos+_tileSize/2);
addChild(actor, 4);
//增加血条
Sprite* bloodsp = Sprite::create("blood.png");
bloodsp->setScaleX(actor->life);
bloodsp->setPosition(Vec2(actor->getContentSize().width/2, actor->getContentSize().height));
actor->addChild(bloodsp);
bloodsp->setTag(actor->Tag);
//增加血条
//把人物存放到容器中
friendArray.pushBack(actor);
actor->setName(actor->ActorName);
}else{
auto actor = EnemySprite::MyCreateInit(texture);
actor->setOpacity(100);
//初始化属性值
actor->atk = dict.at("atk").asInt();
actor->Tag = dict.at("tag").asInt();
actor->life = dict.at("life").asInt();
actor->range = dict.at("range").asInt();
actor->atkrange = dict.at("atkrange").asInt();
//
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(EnemySprite::onTouchBegan, actor);
listener->onTouchEnded = CC_CALLBACK_2(EnemySprite::onTouchEnded, actor);
listener->setSwallowTouches(true);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, actor);
//--------------------改了,添加监听
actor->setPosition(pos+_tileSize/2);
addChild(actor, 4);
Sprite* bloodsp = Sprite::create("blood.png");
bloodsp->setScaleX(actor->life);
bloodsp->setPosition(Vec2(actor->getContentSize().width/2, actor->getContentSize().height));
actor->addChild(bloodsp);
bloodsp->setTag(actor->Tag);
//增加坏人存入vector中
enemyArray.pushBack(actor);
actor->setName(actor->ActorName);
}
int width = dict.at("width").asInt();
int height = dict.at("height").asInt();
x /= width;
y /= height;
pos = Vec2(x, y);
actorArray.insert(pos);
}
}
示例10: loadConfig
/*加载资源*/
void ShowLayer::loadConfig(int level)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
m_Level = level;
//初始化随机种子
randNum();
if (level == 3)
{
int rand = CCRANDOM_0_1() * 5;
//加载地图资源
m_Map = CCTMXTiledMap::create("LastMap2.tmx");
m_MaxLength = 1600;
m_MinLength = 0;
//获取地图上player的坐标
TMXObjectGroup* objGoup = m_Map->getObjectGroup("playerPoint");
ValueMap playerPointMap = objGoup->getObject("Player");
float playerX = playerPointMap.at("x").asFloat();
float playerY = playerPointMap.at("y").asFloat();
//创建playerManager
m_PlayerManager = PlayerManager::createWithLevel(Vec2(playerX, playerY + 24), level);
m_PlayerManager->setPosition(Vec2(0, 0));
m_Map->addChild(m_PlayerManager, 3);
//获取地图上怪物坐标
TMXObjectGroup* mobjGoup = m_Map->getObjectGroup("monsterPoint");
ValueVector monsterPoints = mobjGoup->getObjects();
//ValueMap monsterPoint = mobjGoup->getObject("monster1");
//float monsterX = monsterPoint.at("x").asFloat();
//float monsterY = monsterPoint.at("y").asFloat();
PhyscisWorld::createWorld(m_Map, level);
//创建monsterManager
m_MonsterManager = MonsterManager::createWithLevel(monsterPoints, level); //change
m_MonsterManager->setAnchorPoint(Vec2(0, 0));
m_MonsterManager->setPosition(Vec2(0, 0));
m_Map->addChild(m_MonsterManager, 2);
TMXObjectGroup* bobjGoup = m_Map->getObjectGroup("Boss");
ValueMap bossPoint = bobjGoup->getObject("boss");
float bossPointX = bossPoint.at("x").asFloat();
float bossPointY = bossPoint.at("y").asFloat();
m_BossManager = BossManager::createWithLevel(Vec2(bossPointX, bossPointY), level);
m_BossManager->setAnchorPoint(Vec2(0, 0));
m_BossManager->setPosition(Vec2(0, 0));
m_BossManager->setBOrigin(Vec2(bossPointX, bossPointY));
m_Map->addChild(m_BossManager, 2);
//m_boss->setOrigin(Vec2(bossPointX, bossPointY));
//m_boss->setPosition(Vec2(bossPointX, bossPointY));
//this->addChild(m_boss, 3);
m_GodArmManager = GodArmManager::createWithLevel(1, m_PlayerManager, m_MonsterManager, m_BossManager);
m_GodArmManager->setPosition(Vec2(0, 0));
m_Map->addChild(m_GodArmManager, 4);
m_GodArmManager->runPower();
this->schedule(schedule_selector(ShowLayer::Monsterlogic), 0.1f);
this->schedule(schedule_selector(ShowLayer::logic), 1 / 20.0f);
this->schedule(schedule_selector(ShowLayer::Bosslogic), 1.0f);
//认领地图
this->addChild(m_Map, 0, 1);
}
}
示例11:
PushBoxScene::PushBoxScene()
{
TMXTiledMap* mytmx = TMXTiledMap::create("Pushbox/map.tmx");
mytmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
mytmx->setAnchorPoint(Vec2(0,0));
myx = (visibleSize.width - mytmx->getContentSize().width) / 2;
myy = (visibleSize.height - mytmx->getContentSize().height) / 2;
this->addChild(mytmx, 0);
count = 0;
success = 0;
/*mon = Sprite::create("Pushbox/player.png");
mon->setAnchorPoint(Vec2(0, 0));
mon->setPosition(Vec2(SIZE_BLOCK*1+myx, SIZE_BLOCK*8+myy));
mon->setTag(TAG_PLAYER);
this->addChild(mon, 1);*/
TMXObjectGroup* objects = mytmx->getObjectGroup("wall");
//从对象层中获取对象数组
ValueVector container = objects->getObjects();
//遍历对象
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/wall.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x,y+64));
mywall.pushBack(temp);
this->addChild(temp, 1);
}
TMXObjectGroup* objects1 = mytmx->getObjectGroup("box");
//从对象层中获取对象数组
ValueVector container1 = objects1->getObjects();
//遍历对象
for (auto obj : container1) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/box.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mybox.pushBack(temp);
this->addChild(temp, 3);
}
TMXObjectGroup* objects2 = mytmx->getObjectGroup("player");
//从对象层中获取对象数组
ValueVector container2 = objects2->getObjects();
//遍历对象
for (auto obj : container2) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/player.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mon = temp;
this->addChild(temp, 2);
}
TMXObjectGroup* objects3 = mytmx->getObjectGroup("goal");
//从对象层中获取对象数组
ValueVector container3 = objects3->getObjects();
//遍历对象
for (auto obj : container3) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/goal.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mygoal.pushBack(temp);
this->addChild(temp, 1);
}
}
示例12: testTMX
void prep::testTMX()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
//创建游戏
TMXTiledMap* tmx = TMXTiledMap::create("map.tmx");
tmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
tmx->setAnchorPoint(Vec2(0.5, 0.5));
tmx->setName("paopaot");
this->addChild(tmx);
//获取对象层
TMXObjectGroup* objects = tmx->getObjectGroup("bubble");
//对应对象层的对象数组
ValueVector container = objects->getObjects();
//遍历
for (auto obj : container) {
ValueMap values = obj.asValueMap();
//获取坐标(cocos2dx坐标)
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto buble = Sprite::create("bubble.png");
buble->setPosition(Vec2(x, y + 64));
buble->ignoreAnchorPointForPosition(true);
tmx->addChild(buble, 2);
prep::bubbles.pushBack(buble);
}
objects = tmx->getObjectGroup("wall");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto wall = Sprite::create("wall.png");
wall->setPosition(Vec2(x, y + 64));
wall->ignoreAnchorPointForPosition(true);
tmx->addChild(wall, 1);
prep::walls.pushBack(wall);
}
objects = tmx->getObjectGroup("money");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto goal = Sprite::create("money.png");
goal->setPosition(Vec2(x, y + 64));
goal->ignoreAnchorPointForPosition(true);
tmx->addChild(goal, 1);
prep::money.pushBack(goal);
}
objects = tmx->getObjectGroup("player");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto player = Sprite::create("player.png");
player->setPosition(Vec2(x, y + 64));
player->ignoreAnchorPointForPosition(true);
player->setName("player");
tmx->addChild(player, 1);
}
}