本文整理汇总了C++中TMXObjectGroup类的典型用法代码示例。如果您正苦于以下问题:C++ TMXObjectGroup类的具体用法?C++ TMXObjectGroup怎么用?C++ TMXObjectGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TMXObjectGroup类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CCASSERT
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
{
CCASSERT(groupName.size() > 0, "Invalid group name!");
if (_objectGroups.size()>0)
{
TMXObjectGroup* objectGroup = nullptr;
for (auto iter = _objectGroups.cbegin(); iter != _objectGroups.cend(); ++iter)
{
objectGroup = *iter;
if (objectGroup && objectGroup->getGroupName() == groupName)
{
return objectGroup;
}
}
}
// objectGroup not found
return nullptr;
}
开发者ID:602147629,项目名称:PlanetWar,代码行数:20,代码来源:CCFastTMXTiledMap.cpp
示例2: addChild
bool GameScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
if(NULL==map){
map=TMXTiledMap::create("map/map1.tmx");
}
//map->setScale(2);
addChild(map);
TMXObjectGroup *objects = map->getObjectGroup("player");
CCASSERT(NULL != objects, "'Objects' object group not found");
auto spawnPoint = objects->getObject("playerinit");
CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
int x = spawnPoint["x"].asInt();
int y = spawnPoint["y"].asInt();
Player * player = new Player();
global->player=player;
global->map=map;
player->setPosition(Vec2(x,y));
addChild(player,2);
//player->sprite->runAction(RepeatForever::create(Animate::create(global->createAni(player->texture, 3))));
TMXObjectGroup *object2=map->getObjectGroup("Event");
auto transitionpoint=object2->getObject("transitionEvent");
int x1=transitionpoint["x"].asInt();
int y1=transitionpoint["y"].asInt();
transitionPosition=Vec2(x1,y1);
//CCLOG("over");
this->runAction(CCFollow::create(player,CCRectMake(0,0,map->getContentSize().width,map->getContentSize().height)));
schedule(schedule_selector(GameScene::updateEvent), 0.1);
return true;
}
开发者ID:dingyp,项目名称:MyGame,代码行数:40,代码来源:GameScene.cpp
示例3: CC_UNUSED_PARAM
//.........这里部分代码省略.........
tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap());
tmxMapInfo->setParentElement(TMXPropertyTile);
}
}
else if (elementName == "layer")
{
TMXLayerInfo *layer = new (std::nothrow) TMXLayerInfo();
layer->_name = attributeDict["name"].asString();
Size s;
s.width = attributeDict["width"].asFloat();
s.height = attributeDict["height"].asFloat();
layer->_layerSize = s;
Value& visibleValue = attributeDict["visible"];
layer->_visible = visibleValue.isNull() ? true : visibleValue.asBool();
Value& opacityValue = attributeDict["opacity"];
layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.asFloat());
float x = attributeDict["x"].asFloat();
float y = attributeDict["y"].asFloat();
layer->_offset.set(x, y);
tmxMapInfo->getLayers().pushBack(layer);
layer->release();
// The parent element is now "layer"
tmxMapInfo->setParentElement(TMXPropertyLayer);
}
else if (elementName == "objectgroup")
{
TMXObjectGroup *objectGroup = new (std::nothrow) TMXObjectGroup();
objectGroup->setGroupName(attributeDict["name"].asString());
Vec2 positionOffset;
positionOffset.x = attributeDict["x"].asFloat() * tmxMapInfo->getTileSize().width;
positionOffset.y = attributeDict["y"].asFloat() * tmxMapInfo->getTileSize().height;
objectGroup->setPositionOffset(positionOffset);
tmxMapInfo->getObjectGroups().pushBack(objectGroup);
objectGroup->release();
// The parent element is now "objectgroup"
tmxMapInfo->setParentElement(TMXPropertyObjectGroup);
}
else if (elementName == "image")
{
TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back();
// build full path
std::string imagename = attributeDict["source"].asString();
tileset->_originSourceImage = imagename;
if (_TMXFileName.find_last_of("/") != string::npos)
{
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
tileset->_sourceImage = dir + imagename;
}
else
{
tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
}
}
else if (elementName == "data")
{
开发者ID:114393824,项目名称:Cocos2dxShader,代码行数:67,代码来源:CCTMXXMLParser.cpp
示例4: ScoreManager
// on "init" you need to initialize your instance
bool GameWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
instance = this;
scoreManager = new ScoreManager();
npcManager = new NpcManager();
structureManager = new StructureManager();
touchLocation = ccp(-1, -1);
auto rootNode = CSLoader::createNode("MainScene.csb");
addChild(rootNode);
_tileMap = TMXTiledMap::create("greenmap.tmx");
pathFinding = new PathFinding();
_background = _tileMap->layerNamed("Background");
TMXObjectGroup *objectGroup = _tileMap->objectGroupNamed("Objects");
if (objectGroup == NULL){
return false;
}
auto spawnPoints = objectGroup->objectNamed("spawnPoint");
int x = spawnPoints.at("x").asInt();
int y = spawnPoints.at("y").asInt();
this->addChild(_tileMap);
player = new Player(ccp(x, y));
_meta = _tileMap->layerNamed("Meta");
_meta->setVisible(false);
CCPoint cp1 = tileCoordForPosition(ccp(798, 444));
CCPoint cp2 = tileCoordToPosition(cp1);
//CCLOG("x: %f, y: %f", cp2.x, cp2.y);
this->addChild(player->entityImage, 2);
this->setViewPointCenter(player->entityImage->getPosition());
heartsprite = new cocos2d::Sprite();
heartsprite->initWithFile("heart.png");
heartsprite->setScale(1.5f, 1.5f);
heartsprite->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(30, 60))));
this->addChild(heartsprite, 3);
healthLabel = Label::createWithTTF(std::to_string(player->currentHealth), "kenney-rocket.ttf", 32);
healthLabel->setColor(cocos2d::Color3B::RED);
healthLabel->enableOutline(Color4B(0,0,0,255),3);
healthLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(114, 60))));
this->addChild(healthLabel, 3);
scoreTextLabel = Label::createWithTTF("Score:", "kenney-rocket.ttf", 24);
scoreTextLabel->enableOutline(Color4B(0,0,0,255),3);
scoreTextLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(100, 100))));
this->addChild(scoreTextLabel, 3);
scoreLabel = Label::createWithTTF(std::to_string(scoreManager->getScore()), "kenney-rocket.ttf", 32);
scoreLabel->enableOutline(Color4B(0,0,0,255),4);
pointlocation = this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(110, 130)));
scoreLabel->setPosition(pointlocation);
this->addChild(scoreLabel, 3);
keyboardListener();
this->scheduleUpdate();
this->schedule(schedule_selector(GameWorld::cameraUpdater), 1.0f);
return true;
}
开发者ID:Soxs,项目名称:PMRGame,代码行数:86,代码来源:GameWorld.cpp
示例5: 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();
//.........这里部分代码省略.........
开发者ID:aa13058219642,项目名称:My-Tower-Defents-Freamwork,代码行数:101,代码来源:GameMap.cpp
示例6: 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 );
}
开发者ID:kyejune,项目名称:TilemapTest,代码行数:63,代码来源:DebugMap.cpp
示例7: init
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
_tileMap = TMXTiledMap::create("ai_map.tmx");
//_tileMap->initWithTMXFile("ai_map.tmx");
_background = _tileMap->getLayer("Background");
_foreground_1 = _tileMap->getLayer("Foreground_1");
_foreground_2 = _tileMap->getLayer("Foreground_2");
_meta = _tileMap->getLayer("Meta");
_meta->setVisible(false);
this->addChild(_tileMap);
TMXObjectGroup *objectGroup = _tileMap->getObjectGroup("Objects");
CCASSERT(NULL != objectGroup, "SpawnPoint object not found");
auto spawnPoint = objectGroup->getObject("SpawnPoint");
CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
//CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
//int x = ((CCString)spawnPoint.valueForKey("x")).intValue();
//int y = ((CCString)spawnPoint.valueForKey("y")).intValue();
int x = spawnPoint["x"].asInt();
int y = spawnPoint["y"].asInt();
// player
_player = Sprite::create("egg.png");
_player->setTag(5);
_player->setPosition(x,y);
addChild(_player);
setViewPointCenter(_player->getPosition());
// patrol enemy
searching_enemy = Enemys::createWithLayer(this);
searching_enemy->setGameLayer(this);
auto enemy = objectGroup->getObject("EnemySpawn1");
int x_1 = enemy["x"].asInt();
int y_1 = enemy["y"].asInt();
addEnemyAtPos(Point(x_1,y_1));
_enemies.pushBack(searching_enemy);
// archer
archer = Sprite::create("Kiwi.png");
archer->setPosition(positionForTileCoord(Point(12, 4)));
archer->setTag(23);
archer->setScale(1.0);
this->addChild(archer,1);
_enemies.pushBack(archer);
//boss
boss = Sprite::create("patrol.png");
boss->setPosition(positionForTileCoord(Point(26,9)));
boss->setTag(26);
boss->setScale(1.7);
this->addChild(boss);
_enemies.pushBack(boss);
//a princess
princess = Sprite::create("Princess.png");
princess->setPosition(positionForTileCoord(Point(28, 10)));
princess->setScale(0.6);
this->addChild(princess);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [&](Touch* touch, Event* unused_event)->bool { return true; };
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
// a pause button
auto pauseItem = MenuItemImage::create("pause.png","",CC_CALLBACK_1(HelloWorld::onPause, this));
auto menu = Menu::create(pauseItem,NULL);
pauseItem->setScale(0.2);
pauseItem->setPosition(positionForTileCoord(Point(27, 1)));
menu->setPosition(Point::ZERO);
this->addChild(menu,1,5);
// add background music
//CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("SummerNight.wav");
// navigation button:up, down, left and right and an attacking button
auto left_btn = Sprite::create("left.png");
left_btn->setScale(0.3);
left_btn->setPosition(Point(100, 125));
left_btn->setTag(TAG_LEFT);
this->addChild(left_btn,1);
auto right_btn = Sprite::create("right.png");
right_btn->setScale(0.3);
right_btn->setPosition(Point(250, 125));
//.........这里部分代码省略.........
开发者ID:quanfei,项目名称:ec327-TeamAwesome,代码行数:101,代码来源:HelloWorldScene.cpp
示例8: 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);
}
}
开发者ID:duongbadu,项目名称:chessgame,代码行数:94,代码来源:GameMap.cpp
示例9: 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);
}
}
开发者ID:1900zyh,项目名称:SYSU_Win8App,代码行数:69,代码来源:prep.cpp
示例10: onEnter
void GameLayer::onEnter()
{
Layer::onEnter();
auto visibleSize = Director::getInstance()->getVisibleSize();
this->m_origin = Director::getInstance()->getVisibleOrigin();
m_pTiledMap = TMXTiledMap::create("TYCHEs_COFEE.tmx");
m_TiledMapSize.setSize(m_pTiledMap->getMapSize().width * m_pTiledMap->getTileSize().width, m_pTiledMap->getMapSize().height * m_pTiledMap->getTileSize().height);
this->addChild(m_pTiledMap);
TMXObjectGroup *objects = m_pTiledMap->getObjectGroup("Objects");
CCASSERT(NULL != objects, "'Objects' object group not found");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("hero.plist");
auto spawnPoint = objects->getObject("SpawnPoint");
CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
Point heroInitPos = m_origin + Point(spawnPoint["x"].asFloat(), spawnPoint["y"].asFloat());
m_pHero = Hero::create();
m_pHero->setScale(0.5f);
m_pHero->setPosition(heroInitPos);
m_pHero->runIdleAction();
m_pHero->setLocalZOrder(visibleSize.height - m_pHero->getPositionY());
m_pHero->setHP(100);
m_pHero->setIsAttacking(false);
m_pHero->setJumpStage(0);
m_pHero->onDeadCallback = CC_CALLBACK_0(GameLayer::onHeroDead, this, m_pHero);
m_pHero->attack = CC_CALLBACK_0(GameLayer::onHeroAttack, this);
m_pHero->stop = CC_CALLBACK_0(GameLayer::onHeroStop, this);
m_pHero->walk = CC_CALLBACK_1(GameLayer::onHeroWalk, this);
m_pHero->jump = CC_CALLBACK_1(GameLayer::onHeroJump, this);
this->addChild(m_pHero);
auto centerOfView = Point(visibleSize.width / 2, visibleSize.height / 2);
this->setPosition(centerOfView - m_pHero->getPosition());
m_pForesight = Foresight::create();
this->addChild(m_pForesight);
JsonParser* parser = JsonParser::createWithFile("Debug.json");
parser->decodeDebugData();
auto list = parser->getList();
for (auto& v : list)
{
ValueMap row = v.asValueMap();
for (auto& pair : row)
{
CCLOG("%s %s", pair.first.c_str(), pair.second.asString().c_str());
if (pair.first.compare("HeroHSpeed") == 0)
{
float s = pair.second.asFloat();
m_pHero->setWalkVelocity(s);
}
else if (pair.first.compare("HeroVSpeed") == 0)
{
m_pHero->setJumpVelocity(pair.second.asFloat());
}
else if (pair.first.compare("BulletPower") == 0)
{
m_pHero->setBullletPower(pair.second.asInt());
}
else if (pair.first.compare("BulletSpeed") == 0)
{
m_pHero->setBulletLaunchVelocity(pair.second.asFloat());
}
else if (pair.first.compare("BulletDisappearTime") == 0)
{
m_pHero->setBulletDisappearTime(pair.second.asFloat());
}
else if (pair.first.compare("BulletAngle") == 0)
{
m_pHero->setBullletAngle(pair.second.asInt());
}
else if (pair.first.compare("BulletInterval") == 0)
{
m_pHero->setBulletInterval(pair.second.asFloat());
}
else if (pair.first.compare("WorldG") == 0)
{
//getScene()->getPhysicsWorld()->setGravity(Vec2(0.f, pair.second.asFloat()));
}
else if (pair.first.compare("ForesightSpeed") == 0)
{
initForesight(pair.second.asFloat());
}
else if (pair.first.compare("AmmoCapacity") == 0)
{
m_pHero->setMaxAmmoCapacity(pair.second.asInt());
m_pHero->setAmmoCapacity(pair.second.asInt());
}
}
}
//.........这里部分代码省略.........
开发者ID:jeffcai8888,项目名称:SpaceX,代码行数:101,代码来源:GameLayer.cpp
示例11: CC_CALLBACK_1
void PlayMapSix::onEnter() {
Layer::onEnter();
bisover = false;
//visibleSize,屏幕尺寸
visibleSize = Director::getInstance()->getVisibleSize();
//添加碰撞监听器
contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(PlayMapSix::onContactBegin, this);
contactListener->onContactPostSolve = CC_CALLBACK_2(PlayMapSix::onContactPostSolve, this);
contactListener->onContactPreSolve = CC_CALLBACK_2(PlayMapSix::onContactPreSolve, this);
contactListener->onContactSeparate = CC_CALLBACK_1(PlayMapSix::onContactSeparate, this);
//事件分发器
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
//网格地图
auto winSize = Director::getInstance()->getWinSize();
//map00瓦片地图地图
tilemap = TMXTiledMap::create("map/map6.tmx");
tilemap->setAnchorPoint(Vec2(0,0));
tilemap->setPosition(Vec2(0,0));
//auto group = tilemap->getObjectGroup("objects");
this->addChild(tilemap,-1);
TMXObjectGroup *objects = tilemap->getObjectGroup("objLayer");
CCASSERT(NULL != objects, "'Objects' object group not found");
auto spawnPoint = objects->getObject("hero");
CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
print_x = spawnPoint["x"].asInt();
print_y = spawnPoint["y"].asInt();
TMXLayer* layer = tilemap->getLayer("collideLayer");//从map中取出“bricks”图层
//这个循环嵌套是为了给每个砖块精灵设置一个刚体
int count = 0;
for (int y = 0; y<TMX_HEIGHT; y++)
{
log("xxxxxxxxxxxxxxxxxxxx:%d", y); int groundcounter = 0; int deadlinecounter = 0; int dispearcounter = 0; int bodycounter = 0;
Point groundpoint, deadlinepoint, dispearpoint, bodypoint; Size groundsize, deadlinesize, dispearsize, bodysize;
for (int x = 0; x<TMX_WIDTH; x++)
{
int gid = layer->getTileGIDAt(Vec2(x, y));
Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵
if (gid == GROUND_GID) {
log("sssssssssss %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
if (groundcounter == 0) {
groundpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
groundsize = sprite->getContentSize();
log("groundcounter==0");
}
groundcounter++; log("groundcounter=%d", groundcounter);
}
else {
if (groundcounter != 0) {
log("make execute!");
groundsize = Size(groundsize.width*groundcounter, groundsize.height);
log("point=%f %f,size=%f %f", groundpoint.x, groundpoint.y, groundsize.width, groundsize.height);
this->makePhysicsObjAt(groundpoint, groundsize, false, 0, 0.0f, 0.0f, 0, GROUND_GID, -1);
}
groundcounter = 0;
}/////////////////
if (gid == DEAD_LINE_GID) {
log("sssssssssss %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
if (deadlinecounter == 0) {
deadlinepoint = Point(sprite->getPosition().x, sprite->getPosition().y);
deadlinesize = sprite->getContentSize();
log("groundcounter==0");
}
deadlinecounter++; log("groundcounter=%d", deadlinecounter);
}
else {
if (deadlinecounter != 0) {
log("make execute!");
deadlinesize = Size(deadlinesize.width*deadlinecounter, deadlinesize.height);
log("point=%f %f,size=%f %f", deadlinepoint.x, deadlinepoint.y, deadlinesize.width, deadlinesize.height);
this->makePhysicsObjAt(deadlinepoint, deadlinesize, false, 0, 0.0f, 0.0f, 0, DEAD_LINE_GID, -1);
}
deadlinecounter = 0;
}
if (gid == CAN_DISPEAR_GID) {
sprite->setTag(count);
log("sprite->setTag(%d);", count);
log("sssssssssss %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
if (dispearcounter == 0) {
dispearpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
dispearsize = sprite->getContentSize();
log("groundcounter==0");
}
dispearcounter++; log("groundcounter=%d", dispearcounter);
}
else {
//.........这里部分代码省略.........
开发者ID:MulticsYin,项目名称:Archer-cocos2d-x,代码行数:101,代码来源:PlayMapSix.cpp
示例12: CC_CALLBACK_2
// on "init" you need to initialize your instance
bool HelloWorld::init() {
//////////////////////////////
// 1. super init first
if ( !Layer::init() ){
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/* REGISTERING TOUCH EVENTS
===================================================== */
auto controls = EventListenerTouchAllAtOnce::create();
controls->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(controls, this);
/* NOTE: don't get in the habit of using auto everywhere
An iron price to be paid (extra time == life) masquerading as convenience
No reference can be made with auto and makes code unreadable
Justified here since controls is a one-off and will not
be referenced anywhere else but in this temporal block
ALSO: This is what is called a observer pattern in the industry
controls would be an "interface" of known `subscribers` to the _eventDispatcher `publisher`
and events are "published" to the subscribers as they happen. Interface just means a
contractual agreement between different parts of code to follow a uniform language
*/
/* CREATE A TMXTILEDMAP AND EXTRACT LAYER FOR DISPLAY
===================================================== */
_tileMap = TMXTiledMap::create("TileMap.tmx");
// DEPRECATED: _tileMap = new CCTMXTiledMap();
// _tileMap->initWithTMXFile("TileMap.tmx");
_background = _tileMap->getLayer("Background");
// DEPRECATED: _tileMap->layerNamed("Background");
_meta = _tileMap->layerNamed("Meta");
_meta->setVisible(false);
this->addChild(_tileMap);
TMXObjectGroup *objectGroup = _tileMap->objectGroupNamed("Objects");
// DEPRECATED: CCTMXObjectGroup *objectGroup = _tileMap->objectGroupNamed("Objects");
if(objectGroup == NULL) {
CCLOG("tile map has no Objects object layer");
// DEPRECATED: CCLog("tile map has no objects object layer");
return false;
}
ValueMap spawnPoint = objectGroup->objectNamed("SpawnPoint");
// DEPRECATED: CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
Vec2 spawnHere = Point(300, 300);
if(spawnPoint.size() != 0) {
CCLOG("LOGCAT!!! There is a spawn point");
} else {
CCLOG("LOGCAT!!! There isn't a spawn point. Using default 300 x 300.");
}
_player = Sprite::create("Player.png");
_player->setPosition(spawnHere);
this->addChild(_player);
this->setViewPointCenter(_player->getPosition());
this->setTouchEnabled(true);
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// create menu, it's an autorelease object
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
return true;
}
开发者ID:proxxzy,项目名称:TileMapV3.2,代码行数:87,代码来源:HelloWorldScene.cpp
示例13:
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);
}
}
开发者ID:Coding-Le,项目名称:SE-Cocos2d-Course,代码行数:79,代码来源:PushBoxScene.cpp
示例14: if
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);
//.........这里部分代码省略.........
开发者ID:253627764,项目名称:BadGame,代码行数:101,代码来源:MapAnalysis.cpp
示例15: randNum
/*加载资源*/
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(
|
请发表评论