本文整理汇总了C++中CCTMXTiledMap::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXTiledMap::addChild方法的具体用法?C++ CCTMXTiledMap::addChild怎么用?C++ CCTMXTiledMap::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXTiledMap
的用法示例。
在下文中一共展示了CCTMXTiledMap::addChild方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
// on "init" you need to initialize your instance
bool MapScene::init()
{
if ( !CCLayer::init() )
{
return false;
}
//初始化地图
CCTMXTiledMap *map = CCTMXTiledMap::create("iso-test-zorder.tmx");
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
map->setPosition(ccp(-s.width/2 + winSize.width/2,0));
//初始化人物
m_tamara = CCSprite::create("grossinis_sister1.png");
map->addChild(m_tamara, map->getChildren()->count() );
m_tamara->retain();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
int mapHeight = map->getMapSize().height * map->getTileSize().height;
m_tamara->setPosition(ccp( mapWidth/2,112));
m_tamara->setAnchorPoint(ccp(0.5f,0));
setTouchEnabled(true);
scheduleUpdate();
vmove = -1;
hmove = -1;
stepindex = -1;
myastar = new Astar();
return true;
}
示例2: initCommons
//private
void RPGDialogLayer::initCommons(string titleStr)
{
CCTMXTiledMap *mainBg = CCTMXTiledMap::create("alert_style1.tmx");
float x = (CCDirector::sharedDirector()->getWinSize().width - mainBg->getContentSize().width) / 2.0f;
float y = (CCDirector::sharedDirector()->getWinSize().height - mainBg->getContentSize().height) / 2.0f;
mainBg->setPosition(ccp(x, y));
mainBg->setTag(kRPGDialogLayerBg);
this->addChild(mainBg);
CCLabelTTF *titleLab = CCLabelTTF::create(titleStr.c_str(), "Arial", 25, CCSizeMake(mainBg->getContentSize().width, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
titleLab->setPosition(ccp(190, 135));
titleLab->setColor(ccc3(255, 255, 255));
mainBg->addChild(titleLab);
CCMenu *menu = CCMenu::create();
menu->setAnchorPoint(CCPointZero);
menu->setPosition(CCPointZero);
menu->setTag(kRPGDialogLayerBgMenu);
mainBg->addChild(menu);
}
示例3: init
// on "init" you need to initialize your instance
bool MapScene::init()
{
//地图背景层
CCSprite *bg = CCSprite::create("background.png");
bg->setScale(1.5f);
addChild(bg, 0);
//地图初始化
CCTMXTiledMap *map = CCTMXTiledMap::create("ortho-objects.tmx");
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
int mapHeight = map->getMapSize().height * map->getTileSize().height;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
map->setPosition(ccp(0,0));
//初始化主角
gameplayer = CCSprite::create("grossini.png");
enemy = CCSprite::create("SpinningPeas.png");
map->addChild(gameplayer, map->getChildren()->count() );
map->addChild(enemy, map->getChildren()->count() );
//初始化敌人
enemy->setPosition(ccp(winSize.width/2 + 80,32));
enemy->setAnchorPoint(ccp(0.5f,0));
gameplayer->setPosition(ccp(winSize.width/2,32));
gameplayer->setAnchorPoint(ccp(0.5f,0));
setTouchEnabled(true);
scheduleUpdate();
hmove = 0;
vmove = 0;
enemymovetick = 0;
//主角矩形区域大小
ownsize = CCSizeMake(40,100);
//敌人矩形区域大小
othersize = CCSizeMake(32,32);
//是否是受伤状态
isreduce = false;
return true;
}
示例4: createDragon
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);
}
示例5: init
bool MPMapLayer::init()
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// Exit button
CCMenuItemImage *backItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(MPMapLayer::titleCallback));
backItem->setPosition(ccp(origin.x + visibleSize.width - backItem->getContentSize().width/2 ,
origin.y + backItem->getContentSize().height/2));
CCMenu* menu = CCMenu::create(backItem, NULL);
menu->setPosition(CCPointZero);
this->addChild(menu, 1);
// Screen Title
CCLabelTTF* label = CCLabelTTF::create("A Map Scene", "Arial", TITLE_FONT_SIZE);
label->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label, 1);
// Tile Map
// CCTMXTiledMap *map = CCTMXTiledMap::create("MP_map/desert.tmx");
CCTMXTiledMap *map = CCTMXTiledMap::create("andrew_map/andrew_tilemap.tmx");
this->addChild(map, 0);
MPMapLayer::antiAliasMap(map);
map->setAnchorPoint(ccp(.5, .5));
map->setPosition(ccp(visibleSize.width * .5, visibleSize.height * .5));
map->setScale(.5);
CCTMXLayer* layer = map->layerNamed("Background");
assert(layer != NULL);
CCTMXObjectGroup *objectGroup = map->objectGroupNamed("SpawnPointLayer");
assert(objectGroup != NULL);
CCSize mapSize = map->getContentSize();
float mapHeight = mapSize.height;
float mapWidth = mapSize.width;
player = CCSprite::create("andrew_map/Player.png");
CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
map->addChild(player,1);
const CCString *positionX = spawnPoint->valueForKey("x");
const CCString *positionY = spawnPoint->valueForKey("y");
const CCString *objectName = spawnPoint->valueForKey("name");
std::cout << positionX->getCString() << std::endl;
std::cout << mapHeight - positionY->intValue() % 32 << std::endl;
std::cout << objectName->getCString() << std::endl;
// player->setPosition(ccp(positionX,positionY));
/*
CCSprite *tile = layer->tileAt(ccp(5,6));
assert(tile != NULL);
layer->removeTileAt(ccp(5, 6));
CCActionInterval* actionBy = CCMoveBy::create(2, ccp(visibleSize.width * .5, visibleSize.height * .5));
map->runAction(actionBy);
CCActionInterval* action = CCScaleBy::create(2, 2);
map->runAction(action);
*/
/*
CCSize s = layer->getLayerSize();
for (int x = 2; x < s.width; x++) {
for (int y = 0; y < s.height; y++) {
layer->removeTileAt(ccp(x, y));
}
}
*/
return true;
}
示例6: startPlay
//private
void RPGMapSceneLayer::startPlay(float delay)
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
//数据库部分,读取npc数据
CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString());
while(!query.eof())
{
float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH;
float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT;
bool autoMove = query.getIntField("auto_move") == 1 ? true : false;
RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove);
npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id"));
npc->setPosition(ccp(x, y));
bgMap->addChild(npc);
query.nextRow();
}
query.finalize();
//player
int defaultSpriteFrameIndex = 1; //默认为向下
if(this->m_mapData.playerDirection.compare("up") == 0)
{
defaultSpriteFrameIndex = 10;
}
else if(this->m_mapData.playerDirection.compare("left") == 0)
{
defaultSpriteFrameIndex = 4;
}
else if(this->m_mapData.playerDirection.compare("right") == 0)
{
defaultSpriteFrameIndex = 7;
}
RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex);
player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT));
player->setTag(kRPGMapSceneLayerTagPlayer);
player->m_type = kRPGMapRoleSpriteTypePlayer;
bgMap->addChild(player);
CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png");
CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png");
OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false);
joystick->setTag(kRPGMapSceneLayerTagJoystick);
joystick->m_target = this;
joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc);
this->addChild(joystick);
//menu
CCMenu *mainMenu = CCMenu::create();
mainMenu->setTag(kRPGMapSceneLayerTagMainMenu);
mainMenu->setAnchorPoint(ccp(0.5, 0.5));
mainMenu->setPosition(CCPointZero);
mainMenu->setContentSize(bgMap->getContentSize());
bgMap->addChild(mainMenu);
CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu));
menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35));
menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand);
menuCommand->setRotation(180);
menuCommand->setScale(0.75);
mainMenu->addChild(menuCommand);
// CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
this->scheduleUpdate();
}
示例7: onMenu
void RPGBattleMenu::onMenu(cocos2d::CCObject *pObject)
{
CCMenuItem *menuItem = (CCMenuItem*)pObject;
SimpleAudioEngine::sharedEngine()->playEffect("audio_effect_btn.wav");
switch (menuItem->getTag())
{
case kRPGBattleMenuTagSkill:
{
CCLog("技能");
this->hideMenu();
this->m_selectedMenuTag = kRPGBattleMenuTagSkill;
CCMenuItemSprite *menuCancel = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGBattleMenu::onMenu));
menuCancel->setPosition(ccp(43, 596));
menuCancel->setTag(kRPGBattleMenuTagCancel);
menuCancel->setScale(0.75);
this->addChild(menuCancel);
CCTMXTiledMap *selectLayer = CCTMXTiledMap::create(CCString::createWithFormat("battle_select_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString());
selectLayer->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - selectLayer->getContentSize().width) / 2, (CCDirector::sharedDirector()->getWinSize().height - selectLayer->getContentSize().height) / 2));
selectLayer->setTag(kRPGBattleSceneLayerTagSkillSelectDialog);
((RPGBattleSceneLayer*)this->m_parentNode)->addChild(selectLayer);
((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(true);
//显示title和分隔线
addLab(selectLayer, 199, (CCString*)this->m_stringList->objectForKey("skill_title"), 25, ccp(310, 285));
CCLabelTTF *titleLab = (CCLabelTTF*)selectLayer->getChildByTag(199);
titleLab->setFontFillColor(ccc3(144, 144, 144));
CCSprite *separate = CCSprite::createWithSpriteFrameName("separate.png");
separate->setPosition(ccp(selectLayer->getContentSize().width / 2, 260));
separate->setScaleX(0.65);
separate->setTag(198);
selectLayer->addChild(separate);
//加载技能数据
CCTableView *tableView = (CCTableView*)selectLayer->getChildByTag(197);
if(!tableView)
{
tableView = CCTableView::create(this, ccp(selectLayer->getContentSize().width, selectLayer->getContentSize().height - 80));
tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(CCSizeZero);
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
tableView->setTag(197);
selectLayer->addChild(tableView);
}
this->m_tableItems->removeAllObjects();
string wq = "";
JsonBox::Value json;
json.loadFromString(this->m_playerData->m_skill.c_str());
JsonBox::Array jsonArr = json.getArray();
for (int i = 0; i < jsonArr.size(); i++)
{
char* str = (char*)malloc(10 * sizeof(char));
OzgCCUtility::itoa(jsonArr[i].getInt(), str);
wq.append(str);
if(i + 1 < jsonArr.size())
wq.append(", ");
free(str);
}
if((int)wq.length() > 0)
{
CppSQLite3Query query = this->m_db->execQuery(CCString::createWithFormat(SKILL_QUERY, wq.c_str())->getCString());
while(!query.eof())
{
RPGSkillBtnData *skill = RPGSkillBtnData::create();
skill->m_dataId = query.getIntField("id");
skill->m_name = query.getStringField("name_cns");
skill->m_MP = query.getIntField("mp");
skill->m_skillAttack = query.getIntField("skill_attack");
skill->m_type = query.getIntField("type");
skill->m_attr = query.getIntField("attr");
skill->m_enabled = true;
//不能使用技能的情况
if(this->m_playerData->m_MP <= 0 || this->m_playerData->m_HP <= 0)
skill->m_enabled = false;
else if(this->m_playerData->m_MP < skill->m_MP)
skill->m_enabled = false;
this->m_tableItems->addObject(skill);
query.nextRow();
}
query.finalize();
}
tableView->reloadData();
//加载技能数据 end
//.........这里部分代码省略.........