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


C++ TMXLayer::setScale方法代码示例

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


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

示例1: super_init

void SpaceGameLayer::super_init(const char*map_name,uint32_t res_scale) {
  scale = res_scale;
  cocos2d::Layer::init();
  auto director = cocos2d::Director::getInstance();
  this->setScale(1);
  float sf = director->getContentScaleFactor();
  this->setAnchorPoint(cocos2d::Point(0, 0));

  ////////////////////////////////////
  // LEVEL-SETUP - GENERAL
  level = new Level();
  level->loadMap(map_name,scale);
  this->addChild(level);
  level->setPosition(0, 0);
  // Special atribute layers


  string fgs = "foreground";
  int fg_cnt = 1;
  TMXLayer *fg = level->map->getLayer((fgs + std::to_string(fg_cnt)));
  while (fg != NULL) {
    this->addChild(fg, 10);
    fg->setScale(level->getScale());
    fg_cnt++;
    fg = level->map->getLayer((fgs + std::to_string(fg_cnt)));
  }

 
  string bgs = "background";
  int bg_cnt = 1;
  TMXLayer *bg = level->map->getLayer((bgs + std::to_string(bg_cnt)));
 
  while (bg != NULL) {
    bg->setScale(scale);
    background_layers.pushBack(bg);
    bg = level->map->getLayer((bgs + std::to_string(bg_cnt)));
    bg_cnt++;
  }


  ////////////////////////////////////
  // OUTSIDE OF SCREEN RECTANGLE - GENERAL - This rect is used to determine which go's are on/off-screen
  outside_screen = 1.5;
  float screnWidh = director->getWinSize().width*outside_screen;
  float screnHeight = director->getWinSize().height*outside_screen;
  float distanceX = (screnWidh - screnWidh / outside_screen) / 2;
  float distanceY = (screnHeight - screnHeight / outside_screen) / 2;
  screen.setRect(getPositionX() - distanceX, getPositionY() - distanceY, screnWidh, screnHeight);

  if (view_of_screen_rect) {
    screen_draw = cocos2d::DrawNode::create();
    cocos2d::Vec2 rectangle[4];
    rectangle[0] = cocos2d::Vec2(screen.getMinX(), screen.getMinY());
    rectangle[1] = cocos2d::Vec2(screen.getMaxX(), screen.getMinY());
    rectangle[2] = cocos2d::Vec2(screen.getMaxX(), screen.getMaxY());
    rectangle[3] = cocos2d::Vec2(screen.getMinX(), screen.getMaxY());
    screen_draw->drawPolygon(rectangle, 4, cocos2d::Color4F::RED, 1, cocos2d::Color4F::BLUE);
    screen_draw->setAnchorPoint(getAnchorPoint());
    addChild(screen_draw, 3);
  }


  ////////////////////////////////////
  // SPAWN GAME OBJACTS - SPECIFIC
  getObjects(sf);

  if (hero != NULL) {
    setViewPointCenter(hero->getCameraView());
    Hero_Gui *hg = new Hero_Gui();
    hg->hero = hero;
    addChild(hg);
  }
  ////////////////////////////////////
  // MUSIC SETUP - SPECIFIC
  auto mapGroup = level->getMap()->getProperties();
  string track_name = mapGroup["music_track"].asString();
  auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
  if (track_name == "") {
    current_track = "";
    audio->stopBackgroundMusic();
  }
  else if (track_name != current_track) {
    current_track = track_name;
    audio->playBackgroundMusic(track_name.c_str(), true);
  }

}
开发者ID:Cedfelt,项目名称:Outer-Space-2D,代码行数:87,代码来源:SpaceGameLayer.cpp


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